Write a class called Rectangle2D to represent a rectangle in the plane (2 dimensional space). The class
must contain:
- Four points p1, p2, p3 and p4 of type MyPoint.
- Getter methods for the four points.
- A method LinkedList getVertices() that returns a list of the vertices of the
rectangle (so a list of the points).
- A constructor that constructs a Rectangle2D with specified points as coordinates.
- A no-argument constructor that creates the rectangle with points (0, 0), (5, 5) and (0, 5) and
(5,0) - this constructor must call your previous constructor.
- A non-static method double getPerimeterLength() that returns the length of the perimeter of a
rectangle.
Write a main class as follows:
Rectangle2D rect = new Rectangle2D();
double len = rect.getPerimeterLength();
Here is the code for the MyPoint class:
public class MyPoint
{
private double x;
private double y;
public MyPoint(double x, double y)
{
super();
this.x = x;
this.y = y;
}
public void setX(double x) {
this.x = x;
}
public void setY(double y) {
this.y = y;
}
public MyPoint()
{
this(0,0);
}
public double getX()
{
return x;
}
public double getY()
{
return y;
}
public double getDistance(MyPoint P)
{
return Math.sqrt(Math.pow(this.x-P.getX(), 2) + Math.pow(this.y-P.getY(), 2));
}