Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package rectangle;
- public class Rectangle
- {
- private Point p1;
- private Point p2;
- public Rectangle (Point bottomLeft, Point topRight){
- p1 = bottomLeft;
- p2 = topRight;
- }
- public Rectangle (Point bottomLeft, double width, double height){
- p1 = bottomLeft;
- p2 = new Point(p1.getX()+width, p1.getY()+height);
- }
- public double getArea(){
- return (p2.getX()-p1.getX())*(p2.getY()-p1.getY());
- }
- public double getPerimeter(){
- return ((p2.getX()-p1.getX())*2+((p2.getY()-p1.getY())*2));
- }
- public void move (double deltaX, double deltaY){
- double a = p1.getX()+deltaX;
- double b = p1.getY()+deltaY;
- double c = p2.getX()+deltaX;
- double d = p2.getY()+deltaY;
- p1 = new Point(a,b);
- p2 = new Point(c,d);
- }
- @Override
- public String toString(){
- return ("bot-left:" + p1.getX()+", " +p1.getY()+"\ntopRight:"+p2.getX()+","+p2.getY());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement