Meaningless Drivel is fun!*
The moose likes Beginning Java and the fly likes Math in java help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Math in java help" Watch "Math in java help" New topic
Author

Math in java help

Gray Bee
Greenhorn

Joined: Sep 21, 2010
Posts: 2
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!
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
Hi Gray,

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

Regards,
John Eipe.


www.cs-repository.info
John Eipe
Ranch Hand

Joined: May 23, 2008
Posts: 215
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

Joined: Sep 21, 2010
Posts: 2
Thanks, but never mind, I figured it out finally.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Math in java help
 
Similar Threads
class invalid for deserialization
drawRect method !!!
Networked programing code
Help with Java2D gradient bug. I have to finish this before I can collect my paycheck
Problem when repainting rectangles