• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trying to get values for the perimeter and center of a rectangle.

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ( , ) "

 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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...


OK:
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?

Winston
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic