This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Building Blockchain Apps and have Michael Yuan on-line!
See this thread for details.
Win a copy of Building Blockchain Apps this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

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

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • 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: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • 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
 
Think of how dumb the average person is. Mathematically, half of them are EVEN DUMBER. Smart tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!