Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. You are being provided with

Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. 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).

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()

// this is the provided Point class

public class Point

{

//x,y coordinates for a point

private int x;

private int y;

//Constructors

public Point()

{

x = 0;

y = 0;

}

public Point(int x, int y)

{

this.x = x;

this.y = y;

}

public int getX()

{

return x;

}

public int getY()

{

return y;

}

public void setX(int x)

{

this.x = x;

}

public void setY(int y)

{

this.y = y;

}

public String toString()

{

return "x is: " + x + ", y is: " + y;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions