jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes call second constructor? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "call second constructor?" Watch "call second constructor?" New topic
Author

call second constructor?

N. Gonzalez
Greenhorn

Joined: Jul 17, 2005
Posts: 29
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

Joined: Jul 17, 2005
Posts: 29
I also tried this and it didn't work...



Need some direction, please...
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30293
    
150


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.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
N. Gonzalez
Greenhorn

Joined: Jul 17, 2005
Posts: 29
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: call second constructor?