Question: JAVA CODING SUPPLY CODE AND COMMENTS WITH OUTPUT USING NETBEANS Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle, and Square. Use Quadrilateral as
JAVA CODING SUPPLY CODE AND COMMENTS WITH OUTPUT USING NETBEANS
Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle, and Square. Use Quadrilateral as the superclass of the hierarchy. Create and use a Point class to represent the points in each shape. Make the hierarchy as deep (i.e. as many levels) as possible. Specify the instance variables and methods for each class. 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 object's area (except Quadrilateral). Each class should use an area calculation appropriate for that class. The four coordinate points of each figure should be specified in the following order, top left, top right, bottom right, and bottom left. To simplify the calculations, you can assume that the figures have tops and bottoms that are parallel to the x axis.
The following code specifies the coordinates for the four figure types: //Trapezoid coordinate points Point trapezoidTL = new Point(2.0, 4.0); Point trapezoidTR = new Point(5.0, 4.0); Point trapezoidBR = new Point(4.0, 2.0); Point trapezoidBL = new Point(3.0, 2.0); //Parallelogram coordinate points Point parallelogramTL = new Point(2.0, 4.0); Point parallelogramTR = new Point(5.0, 4.0); Point parallelogramBR = new Point(6.0, 2.0); Point parallelogramBL = new Point(3.0, 2.0); //Rectangle coordinate points Point rectangleTL = new Point(2.0, 4.0); Point rectangleTR = new Point(5.0, 4.0); Point rectangleBR = new Point(5.0, 2.0); Point rectangleBL = new Point(2.0, 2.0); //Square coordinate points Point squareTL = new Point(2.0, 4.0); Point squareTR = new Point(4.0, 4.0); Point squareBR = new Point(4.0, 2.0); Point squareBL = new Point(2.0, 2.0);
For those figures the results would be:
run: The area of the trapezoid is: 4.000000 The area of the parallelogram is: 6.000000 The area of the rectangle is: 6.000000 The area of the square is: 4.000000 BUILD SUCCESSFUL (total time: 1 second)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
