Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

call second constructor?

 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My program currently does not increment for each new student object created although this was defined in a larger constructor in the Student class (that calls upon a smaller constructor that generates a student id that should increment for each new student).

I'm uncertain of how to go about accomplishing this.
Should I be creating a whole set of Student objects again, now using the second constructor, because the contstructor I called for the Student object array didn't take the student id as an input parameter?

I barely understand what I'm doing and I've been at this all day...any hints or guidance is appreciated.


 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also tried this and it didn't work...



Need some direction, please...
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34084
337
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

These two lines are giving you the problem. For each object, you set the id to 1000 and then increment it by one. But since this happens for each student, you never get anywhere with the incrementing.

You really want this to be two variables. One to keep track of the current maximum assigned student id and one to keep track of the student id for that particular student. Tip: Think about which one of these needs to be static.
 
N. Gonzalez
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So are you saying one will be a static class variable and one and instance variable?

I guess I'm confused with the instructions that the constructor should generate the student id.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic