Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rect;
- /**
- * Document : Rectangle Created on : 29/09/2014, 12:19:42 Author : Admin
- */
- public class Rectangle
- {
- private Point p1;
- //private Point p2;
- private double w,h;
- public Rectangle(Point bottomLeft, Point topRight)
- {
- p1 = bottomLeft;
- w = topRight.getX() -bottomLeft.getX();
- h = topRight.getY() - bottomLeft.getY();
- //p2 = topRight;
- }
- public Rectangle(Point bottomLeft, double width, double height)
- {
- p1 = bottomLeft;
- w = width;
- h = height;
- // p2 = new Point(p1.getX() + width, p1.getY() + height);
- }
- public double getArea()
- {
- return w * h;
- }
- public double getPerimeter()
- {
- return ((w - p1.getX()) * 2 + ((h - p1.getY()) * 2));
- }
- public void move(double deltaX, double deltaY)
- {
- p1.setX(p1.getX() + deltaX);
- p1.setY(p1.getY() + deltaY);
- }
- @Override
- public String toString()
- {
- return ("bot-left:" + p1, "\ntopRight:" + (new Point()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement