wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes to Dave Lander,Marilyn de Queiroz Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "to Dave Lander,Marilyn de Queiroz" Watch "to Dave Lander,Marilyn de Queiroz" New topic
Author

to Dave Lander,Marilyn de Queiroz

mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
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.


Thank you Oh Lord<br />For the white blind light<br />A city rises from the sea<br />I had a splitting headache<br />from which the future's made<br />--morrisson
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
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.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
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

Joined: Oct 19, 2002
Posts: 43
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 ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: to Dave Lander,Marilyn de Queiroz
 
Similar Threads
Why can student[x] be resolved?
not a statement
Error in calculation
array variables out of scope-why?
arrays