• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

to Dave Lander,Marilyn de Queiroz

 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wanted to show you two the code you helped me build. There is only one problem left. I have to increment the student number for use on the displayGrades() method. I thought what I had in the constructor and get,set methods would work, but it is just not working. Anyways here is all the code so you can(maybe) see what I have going on. Thanks for all the help!

The GradePoint class is called from a class named TestGradePoint which is not included.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The static variable studentNumber is never incremented or otherwise changed after you initialize it to 100.
Also, one of your methods has a parameter named studentNumber, which will hide the static variable of the same name. This is legal but is bad practice.
 
Bill Liteplo
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
This code looks [BOLD]a lot[/BOLD] better than your last post. Way to go!
I notice that your included code doesn't ever set the studentNumber, even though your comments for the constructor mention it.
I think the constructor is a fine place for it.
However, I would avoid having an argument named studentNumber in the method setStudentNumber and also a static variable studentNumber (same name).
I'm guessing you want the student number to start at 100 (maybe 101?), and go up statically from there. Fine.
Then redo setStudentNumber to read

or reverse the two lines in the method to start at 101.
Then just invoke setStudentNumber() in your constructor, and never again. (Notice I made the method private.) If you want the student Number to be determined by something other than a static incrementing variable, then you may need to change this.
Bill
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eureka!!!It works. Thanks for the pointer
stuNo = studentNumber;
studentNumber++;
I got it to work with
stuNo = studentNumber++;
after I realized that I had to call setStudentNumber from the constructor. Once I realized my error it worked. Then I come back to javaranch to find out that was correct. This is beautiful. I spent alot of time on this and learned quite a bit. Although I am happy to be done with this I am still way behind on other things. So before I ramble too long. Thanks for all the help everybody. I am sure I will be back later on, maybe I can even answer questions one day.
[ October 26, 2002: Message edited by: mike hengst ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic