Question: Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy since all other classes are

Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy since all other classes are derived from Quadrilateral. You are being provided with a Point class, use it to represent the points in each shape. For e.g. the private instance variables of Quadrilateral should be the x-y coordinate pairs for the four endpoints of the Quadrilateral. Write a program that instantiates objects of your classes and outputs each objects area (except Quadrilateral). (10 points) Quadrilateral: Data: Point topLeft, topRight, bottomLeft, bottomRight; Methods: Constructors, getters, setters, toString All derived classes: Each derived class must have its own instance data like side for Square, length & width for Rectange and so on. Methods: Constructors, setters, getters, to String, get Area()

HERE IS WHAT I HAVE SO FAR

public class QuadrilateralTest { public static void main(String[] args) {

// A quadrilateral is a four-sided polygon Quadrilateral quadrilateral = new Quadrilateral(1.1, 1.2, 6.6, 2.8, 6.2, 9.9, 2.2, 7.4);

// A trapezoid is a quadrilateral having exactly two parallel sides Trapezoid trapezoid = new Trapezoid(0.0, 0.0, 10.0, 0.0, 8.0, 5.0, 3.3, 5.0);

// A parallelogram is a quadrilateral with opposite sides parallel Parallelogram parallelogram = new Parallelogram(5.0, 5.0, 11.0, 5.0, 12.0, 20.0, 6.0, 20.0);

// A rectangle is an equiangular parallelogram Rectangle rectangle = new Rectangle(17.0, 14.0, 30.0, 14.0, 30.0, 28.0, 17.0, 28.0);

// A square is an equiangular and equilateralparallelogram Square square = new Square(4.0, 0.0, 8.0, 0.0, 8.0, 4.0, 4.0, 4.0);

System.out.printf("%s %s %s %s %s ", quadrilateral, trapezoid, parallelogram, rectangle, square); } } // end class QuadrilateralTest

-----------------------------------

public class Quadrilateral { private Point point1; // first endpoint private Point point2; // second endpoint private Point point3; // third endpoint private Point point4; // fourth endpoint // eight-argument constructor public Quadrilateral(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { point1 = new Point(x1, y1); point2 = new Point(x2, y2); point3 = new Point(x3, y3); point4 = new Point(x4, y4); } // return point1 public Point getPoint1() { return point1; } // return point2 public Point getPoint2() { return point2; } // return point3 public Point getPoint3() { return point3; } // return point4 public Point getPoint4() { return point4; } // return string representation of a Quadrilateral object @Override public String toString() { return String.format("%s: %s", "Coordinates of Quadrilateral are", getCoordinatesAsString()); } // return string containing coordinates as strings public String getCoordinatesAsString() { return String .format("%s, %s, %s, %s ", point1, point2, point3, point4); } } // end class Quadrilateral

--------------------------------------------------

public class Trapezoid extends Quadrilateral { private double height; // height of trapezoid

// constructor public Trapezoid(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { super(x1, y1, x2, y2, x3, y3, x4, y4); }

// return height public double getHeight() { if (getPoint1().getY() == getPoint2().getY()) return Math.abs(getPoint2().getY() - getPoint3().getY()); else return Math.abs(getPoint1().getY() - getPoint2().getY()); }

// return area public double getArea() { return getSumOfTwoSides() * getHeight() / 2.0; }

// return the sum of the trapezoid's two sides public double getSumOfTwoSides() { if (getPoint1().getY() == getPoint2().getY()) return Math.abs(getPoint1().getX() - getPoint2().getX()) + Math.abs(getPoint3().getX() - getPoint4().getX()); else return Math.abs(getPoint2().getX() - getPoint3().getX()) + Math.abs(getPoint4().getX() - getPoint1().getX()); }

// return string representation of Trapezoid object @Override public String toString() { return String.format(" %s: %s%s;: %s %s: %s ", "Coordinates of Trapezoid are", getCoordinatesAsString(), "Height is", getHeight(), "Area is", getArea()); } } // end class Trapezoid

--------------------------------------------------

public class Parallelogram extends Trapezoid { // constructor public Parallelogram(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { super(x1, y1, x2, y2, x3, y3, x4, y4); }

// return width of parallelogram public double getWidth() { if (getPoint1().getY() == getPoint2().getY()) return Math.abs(getPoint1().getX() - getPoint2().getX()); else return Math.abs(getPoint2().getX() - getPoint3().getX()); }

// return string rep of Parallelogram object @Override public String toString() { return String.format(" %s: %s%s: %s %s: %s %s: %s ", "Coordinate of Parallelogram are", getCoordinatesAsString(), "Width is", getWidth(), "Height is", getHeight(), "Area is", getArea()); } } // end class Parallelogram

---------------------------------------------------------------------

public class Square extends Parallelogram { // constructor public Square(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { super(x1, y1, x2, y2, x3, y3, x4, y4); }

// return string representation of Square object @Override public String toString() { return String.format(" %s: %s%s: %s %s: %s ", "Coordinates of Square are", getCoordinatesAsString(), "Side is", getHeight(), "Area is", getArea()); } } // end class Square

---------------------------------------------------------

public class Rectangle extends Parallelogram { // constructor public Rectangle(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) { super(x1, y1, x2, y2, x3, y3, x4, y4); }

// return string representation of Rectangle object @Override public String toString() { return String.format(" %s: %s%s: %s %s: %s %s: %s ", "Coordinates of Rectangle are", getCoordinatesAsString(), "Width is", getWidth(), "Height is", getHeight(), "Area is", getArea()); } } // end class Rectangle

---------------------------------------------------------

public class Point { private double x; // x coordinate private double y; // y coordinate

// two-argument constructor public Point(double x, double y) { this.x = x; this.y = y; }

// return x public double getX() { return x; }

// return y public double getY() { return y; }

// return string rep of Point object @Override public String toString() { return String.format("(%.1f, %.1f)", getX(), getY()); } } // end class point

-------------------------------------

I know that there are several errors with the code but I do not know what to do to fix it so that it would work. I'm hoping you might be able to shed some light on this.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!