• 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

Math in java help

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I'm in my first programming class and I'm having some trouble with part of this assignment. We have to construct concentric rectangles and take the area of the path between then (just subtract the larger from the smaller areas), and then take the diagonals of the rectangles. I have them constructed, but I'm not sure of the syntax for the math operations. Here is the code I have so far.

public static void main (String[] args) {

Rectangle box = new Rectangle(45,55,100,80);
Rectangle box2 = new Rectangle ((int) box.getX()+10, (int)box.getY()+10, (int)box.getWidth()-20, (int) box.getHeight()-20);

System.out.printf("The coordinates of the bigger rectangle are: {(%.0f,%.0f), (%.0f,%.0f),(%.0f,%.0f), (%.0f,%.0f)}%n",
box.getX(), box.getY(), box.getX()+box.getWidth(), box.getY(),
box.getX()+box.getWidth(), box.getY()+box.getHeight(),
box.getX(), box.getY()+box.getHeight());
System.out.printf("The coordinates of the smaller rectangle are: {(%.0f,%.0f), (%.0f,%.0f),(%.0f,%.0f), (%.0f,%.0f)}%n",
box2.getX(), box2.getY(), box2.getX()+box2.getWidth(), box2.getY(),
box2.getX()+box2.getWidth(), box2.getY()+box2.getHeight(),
box2.getX(), box2.getY()+box2.getHeight());


Any help would be appreciated, thanks!
 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Gray,

Welcome to JavaRanch. Please use code tags to submit your code so that it looks nice and aligned.

Regards,
John Eipe.
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look at java documentation to see the list of functions available in Math class.

All the functions defined there are static. So you could call them using a similar syntax like Math.floor(x).

Thanks,
John Eipe.
 
Gray Bee
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but never mind, I figured it out finally.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic