I have create a program that you enter student information in. I think I have all the code right, but when I enter the informantion and then choose option "2" to print out the information entered the integer inputs all come back "0" apart from "StudentID'. Can someone show me where I have gone wrong and what I need to do to fix it?
David Ausere wrote:Any pointers on an easy way to make the Student ID autopopulate for each addition?
Have this field as a static and increment (within constructor) each time an object of a Student class is created.
Probably this is what your teacher is expecting at an academic level.
Welcome to the Ranch and well done understanding the hint about your problem.
A few style things:-
1: A few of your lines are too long. Line 14 would read better as in the code below: this is how you can deal with such long lines.
2: Where you have two different names for the parameter and the field in a constructor (or a set method), give them the same name, as in my version of your constructor below. That way, you can display the best name as a parameter, and use the best name for a field. Note the construct with this.xxx. That means the field called xxx rather than the local variable/parameter xxx. You may be able to improve those field names without my help.
3: You have the Capitalletters in the wrong places in that constructor. Not Lastname but lastName please.
4: No space after ( on line 14 please.
5: There is no need for an empty line at line 24: I have removed it.
6: Your getXXX methods should have a Capital Letter after get: getGrade1 rather than getgrade1 please.
Line 69 could also benefit from breaking into several lines.
Won't you be my neighbor? - Fred Rogers. tiny ad:
Gift giving made easy with the permaculture playing cards