Advertisement
Parasect

r

Sep 29th, 2014
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. package rect;
  2.  
  3. /**
  4. * Document : Rectangle Created on : 29/09/2014, 12:19:42 Author : Admin
  5. */
  6. public class Rectangle
  7. {
  8.  
  9. private Point p1;
  10. //private Point p2;
  11. private double w,h;
  12.  
  13. public Rectangle(Point bottomLeft, Point topRight)
  14. {
  15. p1 = bottomLeft;
  16. w = topRight.getX() -bottomLeft.getX();
  17. h = topRight.getY() - bottomLeft.getY();
  18. //p2 = topRight;
  19. }
  20.  
  21. public Rectangle(Point bottomLeft, double width, double height)
  22. {
  23. p1 = bottomLeft;
  24. w = width;
  25. h = height;
  26. // p2 = new Point(p1.getX() + width, p1.getY() + height);
  27. }
  28.  
  29. public double getArea()
  30. {
  31. return w * h;
  32. }
  33.  
  34. public double getPerimeter()
  35. {
  36. return ((w - p1.getX()) * 2 + ((h - p1.getY()) * 2));
  37. }
  38.  
  39. public void move(double deltaX, double deltaY)
  40. {
  41.  
  42. p1.setX(p1.getX() + deltaX);
  43. p1.setY(p1.getY() + deltaY);
  44. }
  45.  
  46. @Override
  47. public String toString()
  48. {
  49. return ("bot-left:" + p1, "\ntopRight:" + (new Point()));
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement