Justin Bruns wrote:I'm doing a self-taught course and I was given some mangled code to fix up. . . .
And boy, have they mangled it.
What you haven't been told yet:
1: A lot of people dislike // end comments. I myself think they are useful, but that is controversial.2: But I have never seen // begin comments. The comments should be before the class/method and should be surrounded by /** ...*/. Those are documentation comments.So, delete all the begin comments, as well as inane comments like that in
import java.util.Scanner; // uses Scanner
Whoever wrote that knows Java, and has introduced compiler errors into their code. The structure of every method is there, but you need to work out the errors. Do not try to change the structure of any of the methods, at all. If it says
. . . in fact the order of things and the names of things are all correct. People have already told you to get an instance field (it's not called a class field) firstName, and remember the spelling must be exactly the same as in the method to the left of the =. So you add a firstName field to the class, not labelling it static. Then you find out the syntax for methods and you work out where the () go and where the , and where the ; go. And get rid of some of the unnecessary comments.
You work out whether there are any spelling errors like firstname/firstName.
You work out whether there are any { or } out of place; you have already noticed the } for the main method is out of place.
Another thing haven't been told is that the if block ought to have { } in, so put { } and newlines and indentation after the if in the setAge method.
Note, there are no logic errors in that class. It will compile and run if you don't create any methods. You simply need to repair the misspellings, add the three fields, and then you can put something into the main method which will show it working.
A class should have its equals() hashCode() and toString() methods overridden, but I think that is beyond the scope of the
test they have given you.