public class Rectangle {
    private Point p1;
    private Point p2;
    private double area;
    private double perimeter;
    public Rectangle(Point p1, Point p2) {
        this.p1 = p1;
        this.p2 = p2;
        this.area = (Math.abs(this.p1.getX() - this.p2.getX())
                   * Math.abs(this.p1.getY() - this.p2.getY()));
        // You cannot access this.p1.x directly cos it's private
        this.perimeter = (2*(Math.abs(this.p1.getX() - this.p2.getX())
                           + Math.abs(this.p1.getY() - this.p2.getY())));
        // You cannot access this.p1.x directly cos it's private
    }
    public Point getP1() {
        return this.p1;
    }
    public Point getP2() {
        return this.p2;
    }
    public double getArea() {
        return this.area;
    }
    public double getPerimeter() {
        return this.perimeter;
}
    @Override
    public String toString() {
        return "(" + this.p1 + "," + this.p2 + ")";
    }
}
