Trying to get values for the perimeter and center of a rectangle.
Joined: Mar 12, 2012
My assignment wants me to get and return values for a rectangle.
I'm having difficulty getting the perimeter and center values to show up.
I'm also thinking that my code does not look that great for getting values. so if you have any critiques I would be happy to hear them
here are the instructions just in case:
"Have the class define methods to calculate and return values for:
the area of a rectangle: areaRectangle()
the perimeter of the rectangle: perimeterRectangle()
the X value of the center of the rectangle: centerX()
the Y value of the center of the rectangle: centerY()
Be sure to have an applet that has a paint method that first draws a rectangle using
Be careful to change the y values in your drawString calls so they do not overwrite each other and so that the first one is low enough to not be in the way of the drawn rectangle.
Hint: the drawString for the center of the rectangle will probably use a lot of String concatenation to get the point brackets and comma in ( , ) "
kenny gill wrote:I'm also thinking that my code does not look that great for getting values. so if you have any critiques I would be happy to hear them...
First: I would expect to see two classes: A Rectangle, and an Applet (RectangleApplet?) that uses a Rectangle. The added advantage to that is that you don't have to add 'Rectangle' to the names of all your methods.
A good rule to remember: A Rectangle is NOT (necessarily) an Applet; so it doesn't make sense to tie the two together.
Second: You haven't assigned any values to your 'answer2' and 'answer3' fields, so the likelihood is that you're getting 0 (and can you think of better names? It's part of the programmer's art).
Third: Your call to Graphics.drawRect() uses values copied from the values for 'width' and 'height'. How do you think you might do it better?
Isn't it funny how there's always time and money enough to do it WRONG?