Write an inheritance hierarchy for classes Quadrilateral,Trapezoid, parallelogra
ID: 3610470 • Letter: W
Question
Write an inheritance hierarchy for classes Quadrilateral,Trapezoid, parallelogram, Rectangel and Square. UseQuadrilateral as the base class of the hierarchy. Make thehieraracy as deep (i.e. as many levels) as possible. specifythe instance variables, properties and methods for eachclass. The Private instance variables of Quadrilateral shouldbe the x-y coordinate pairs for the four endpoints of theQuadrilateral. Write an application that instantiates objectsof your classes and outputs each object's area (exceptQuadrilateral).Explanation / Answer
Dear... public class Square{ public int base; public int getArea() { return base * base; } } public class Rectangle extends Square { public int height; public int getArea() { return base * height; } } public class Parallelogram extends Rectangle { public double angle; } public class Parallelogram { protected int base; protected int height; protected double angle; public void setAngle(double angle) { this.angle = angle; } } public class Rectangle extends Parallelogram { public void setAngle(double angle) { } } public class Parallelogram { public final int base; public final int height; public final int angle; public Parallelogram(int base, int height, doubleangle) { this.base = base; this.height = height; this.angle = angle; } public int getArea() { return base * height; } } public class Rectangle extends Parallelogram {
public Rectangle(int base, int height) { super(base, height, Math.PI/2); } }
public class Square extends Rectangle
{ public Square(int side) { super(side, side); } } public class Quadrilateral
{ // ... } public class Trapezoid extends Quadrilateral { // ... } public class Parallelogram extends Trapezoid { private int a; private int b; private float angle; public Parallelogram(int pA, int pB, float pAngle) { ... }
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.