• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

call second constructor?

 
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...
 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • 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
Boost this thread!