First programming class, and I don't understand the run-time error I am getting! (writing classes and methods exercise)
This assignment is basically to understand how to write classes and methods. I have written my code from scratch, and it compiles and it runs. My methods that get the perimeter and area do so accurately, but my access methods that just getWidth and getLength always return values of 0.
Does anyone know why this might be the case? Btw, when you look at my code, I'm just going straight from the text, so if you think "why did she do that?" it's me just doing my best to understand from the textbook.
Edit: My code had my real name in it, so I'm removing it now that I have figured it out. Thank you! I don't know how to delete/resolve messages here, but I appreciate the help.
Re: First programming class, and I don't understand the run-time error I am getting! (writing classes and methods exercise)
Welcome to the forum! Thank you for taking the time to learn to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.
And, ironically, your perimeter() and area() methods are wrong. One of the purposes of a class' constructor is to initialize the object's instance variables. Your constructor signature is correct, your class has the instance variables or fields it needs, and you call the constructor properly, but the constructor's empty body does nothing.
Remedy: Modify the constructor so that the parameters passed to it are used to initialize the object's instance variables. Modify the area() and perimeter() methods so that they do not take parameters but use the object's instance variables to calculate the answer that is returned.
Once you've corrected the class, you will likely want to rethink how the main() method tests it.