Question: Create a new class called Quadrilateral that extends Shape and implement the following constructor. protected Quadrilateral(Point[] aPoints) This constructor calls the superclasss constructor and passes
Create a new class called Quadrilateral that extends Shape and implement the following constructor.
protected Quadrilateral(Point[] aPoints)
This constructor calls the superclasss constructor and passes it the name "Quadrilateral". It then passes a copy of the first four entries in the aPoints array to the setPoints method.
Override the following methods.
4
1. public double getPerimeter()
This method calculates the perimeter of the Quadrilateral. The perimeter of a quadrilateral is the sum of the lengths its sides (to get the length of a side, calculate the distance between the two of its vertices).
2. public double getArea()
This method calculates the area of the Quadrilateral. If the vertices of a quadrilateral are A = (ax,ay), B = (bx,by), C = (cx,cy), and D = (dx,dy), then the area of the quadrilateral is given by the expression
[(axby aybx)+(bxcy bycx)+(cxdy cydx)+(dxay dyax)] / 2
Here is my code for shape
import java.awt.Point;
public abstract class Shape {
private String name;
private Point[] points;
protected Shape(String aName) {
this.name = aName;
}
public final String getName() {
return this.name;
}
protected final void setPoints(Point[] thePoints) {
this.points = thePoints;
}
public final Point[] getPoints() {
return this.points;
}
public static double getDistance(Point p1, Point p2) {
double x1 = p1.getX();
double x2 = p2.getX();
double y1 = p1.getY();
double y2 = p2.getY();
double add1 = x1 - x2;
double sqr1 = add1 * add1;
double add2 = y1 - y2;
double sqr2 = add2 * add2;
double sqrt = sqr2 + sqr1;
return Math.sqrt(sqrt);
}
abstract double getPerimeter();// Just Remove Method body
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
