Advertisement
Parasect

rect

Sep 16th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. package rectangle;
  2. public class Rectangle
  3. {
  4.  
  5. private Point p1;
  6. private Point p2;
  7.  
  8. public Rectangle (Point bottomLeft, Point topRight){
  9. p1 = bottomLeft;
  10. p2 = topRight;
  11. }
  12. public Rectangle (Point bottomLeft, double width, double height){
  13. p1 = bottomLeft;
  14. p2 = new Point(p1.getX()+width, p1.getY()+height);
  15. }
  16. public double getArea(){
  17. return (p2.getX()-p1.getX())*(p2.getY()-p1.getY());
  18. }
  19. public double getPerimeter(){
  20. return ((p2.getX()-p1.getX())*2+((p2.getY()-p1.getY())*2));
  21. }
  22. public void move (double deltaX, double deltaY){
  23. double a = p1.getX()+deltaX;
  24. double b = p1.getY()+deltaY;
  25. double c = p2.getX()+deltaX;
  26. double d = p2.getY()+deltaY;
  27. p1 = new Point(a,b);
  28. p2 = new Point(c,d);
  29. }
  30. @Override
  31. public String toString(){
  32. return ("bot-left:" + p1.getX()+", " +p1.getY()+"\ntopRight:"+p2.getX()+","+p2.getY());
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement