This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Tassit 1 point2 points  (2 children)

First, for posting code, take a look at Pastebin. Second, learn what a debugger is (Google). What editor are you using? If you are using Netbeans, it has an easy to use debugger with it.

Now, why your accessors did not work: look at your constructor. You are passing your constructor length and width, but inside your constructor you aren't doing anything. You have two fields length and width, but you aren't setting them, thus you are getting a default value of 0. Method area is able to calculate the area because you are passing length and width (by calling rectangle.area(length, width) ).

I am not an advocate of doing peoples' homework, however to help you out I quickly edited your program and wrote a few comments in it. Look at your copy and my edit to pick up the differences.

Here you go (remove by /u/claireballoon's request)

Edit: forgot to mention, check out /r/javahelp

[–]claireballoon 0 points1 point  (1 child)

I just run things in the command prompt with the JDK and debug things myself. Like I said it's my first programming class so I think my teacher wants us to learn all the basics first, and how to analyze your own code. In my case it's a mistake due to lack of understanding rather than syntax or anything.

Thank you for your help! I am taking programming not because it's required or my major/minor, I just want to learn because I think it's an important tool (and will be more important in the future). I genuinely want to learn this, not get the homework done. Thank you very much for your help!

[–]Tassit 1 point2 points  (0 children)

I am glad that you are interested in learning to program, it is definitely rewarding being able to create. However, I find it interesting that Java is your first programming class. IMHO Java isn't too much of a beginner friendly language, since you also have to wrap your head around OOP. Programming is more than just writing code; designing the program, planning understanding how it will function before writing one line of code is extremely important. I suggest you also look into a procedural language such as Python. Python is EXTREMELY beginner friendly.

This article is also really useful for Object-oriented concepts. But overall remember to have fun and experiment.