Advertisement
atanasovetr

Exercise4

Dec 14th, 2020
627
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. //class RectangleP
  2. public class RectangleP {
  3.     private Point point1;
  4.     private Point point2;
  5.  
  6.     public RectangleP() {
  7.         this.point1 = new Point("point1");
  8.         this.point2 = new Point("point2");
  9.     }
  10.  
  11.     public RectangleP(Point point1, Point point2) {
  12.         this.point1 = point1;
  13.         this.point2 = point2;
  14.     }
  15.     public double perimeter(){
  16.         double width = Math.abs(point1.getX() - point2.getX());
  17.         double height = Math.abs(point1.getY() - point2.getY());
  18.         double peri = 2 * width + 2 * height;
  19.         return peri;
  20.     }
  21.     public double area(){
  22.         double width = Math.abs(point1.getX() - point2.getX());
  23.         double height = Math.abs(point1.getY() - point2.getY());
  24.         double area = width * height;
  25.         return area;
  26.     }
  27.  
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement