Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program should be in Java. Quadrilateral Inheritance Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass

image text in transcribedimage text in transcribedimage text in transcribed

This program should be in Java.

Quadrilateral Inheritance 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 tester program that instantiates each f the objects of your classes and outputs the are of each class except the quadrilateral. (You may need to look up how to find the areas of a trapezoid. class Point (10) Includes x and y coordinates as type double instance variables, an accessor, mutator and toString methods. Includes a default constructor and a constructor with an x and y coordinate. The toString method returns a String with the points in the format (x,y). class Quadrilateral (15) Has four instance variables with the four end points(vertices). Create one constructor that accepts eight numbers of type double (four x,y pairs) and creates 4 points. Create a separate method to access each of the four points. (i.e. getPoint10), getPoint20), getPoint30 getPoint40 Create a returnCoordsAsString method which returns the four pair of coordinates Create a toString method which returns a String with the four coordinates pairs in a printable form as shown in the sample output. class Trapezoid a subclass of Quadrilateral (20) Has one additional variable height. Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the trapezoid. (Assume two of the sides are parallel to either the x-axis or y-axis.) A method getHeight that calculates and returns the height. A method getArea that returns the area of the trapezoid as a double. A method getSumOfTwoSides that returns a double. Here is this method: // return the sum of the trapezoid's two sides public double getSumOfTwoSides() { if (getPoint10.getY0 == getPoint20.getY() { return Math.abs(getPoint10).getX() - getPoint20.getX()) + Math.abs(getPoint30.getX() - getPoint40.getX(); } else { return Math.abs(getPoint20.getX() - getPoint30.getX() + Math.abs(getPoint40.getX() - getPoint10.getX(); } } Create a toString method which returns a String with the four coordinates pairs as well as the height and area of the trapezoid in a printable form as shown in the sample output. class Parallelogram a subclass of Trapezoid (20) Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the parallelogram. Has a method getWidth that returns the width. Use this: // return width of parallelogram public double get Width() { if (getPoint10.getY() == getPoint20.getY() { return Math.abs(getPoint10.getX() - getPoint20.getX(); } else { return Math.abs(getPoint20.getX() - getPoint30.getX(); } } Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the parallelogram in a printable form as shown in the sample output. class Rectangle - a subclass of parallelogram (15) Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the trapezoid. (Assume two of the sides are parallel to either the x-axis or y-axis.) Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the rectangle in a printable form as shown in the sample output. class Square a subclass of parallelogram (15) Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the square in a printable form as shown in the sample output. Use QuadrilateralTest.java to test the program. Download this class from the Programs /Lesson 2/Homework tab Sample Output: Coordinates of quadrilateral are (1.10, 1.20), (6.60, 2.80), (6.20, 9.90), (2.20, 7.40) Coordinates of trapezoid are (0.00, 0.00), (10.00, 0.00), (8.00, 5.00), (3.30, 5.00) Height is: 5.00: Area is 36.75 Coordinates of parallelogram are (5.00, 5.00), (11.00, 5.00), (12.00, 20.00), (6.00, 20.00) Width is 6.00 Height is 15.00 Area is: 90.00 Coordinates of Rectangle are (17.00, 14.00), (30.00, 14.00), (30.00, 28.00), (17.00, 28.00) Width is 13.00 Height is 14.00 Area is: 182.00 Coordinates of square are (4.00, 0.00), (8.00, 0.00), (8.00, 4.00), (4.00, 4.00) Side is 4.00 Area is: 16.00 Quadrilateral Inheritance 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 tester program that instantiates each f the objects of your classes and outputs the are of each class except the quadrilateral. (You may need to look up how to find the areas of a trapezoid. class Point (10) Includes x and y coordinates as type double instance variables, an accessor, mutator and toString methods. Includes a default constructor and a constructor with an x and y coordinate. The toString method returns a String with the points in the format (x,y). class Quadrilateral (15) Has four instance variables with the four end points(vertices). Create one constructor that accepts eight numbers of type double (four x,y pairs) and creates 4 points. Create a separate method to access each of the four points. (i.e. getPoint10), getPoint20), getPoint30 getPoint40 Create a returnCoordsAsString method which returns the four pair of coordinates Create a toString method which returns a String with the four coordinates pairs in a printable form as shown in the sample output. class Trapezoid a subclass of Quadrilateral (20) Has one additional variable height. Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the trapezoid. (Assume two of the sides are parallel to either the x-axis or y-axis.) A method getHeight that calculates and returns the height. A method getArea that returns the area of the trapezoid as a double. A method getSumOfTwoSides that returns a double. Here is this method: // return the sum of the trapezoid's two sides public double getSumOfTwoSides() { if (getPoint10.getY0 == getPoint20.getY() { return Math.abs(getPoint10).getX() - getPoint20.getX()) + Math.abs(getPoint30.getX() - getPoint40.getX(); } else { return Math.abs(getPoint20.getX() - getPoint30.getX() + Math.abs(getPoint40.getX() - getPoint10.getX(); } } Create a toString method which returns a String with the four coordinates pairs as well as the height and area of the trapezoid in a printable form as shown in the sample output. class Parallelogram a subclass of Trapezoid (20) Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the parallelogram. Has a method getWidth that returns the width. Use this: // return width of parallelogram public double get Width() { if (getPoint10.getY() == getPoint20.getY() { return Math.abs(getPoint10.getX() - getPoint20.getX(); } else { return Math.abs(getPoint20.getX() - getPoint30.getX(); } } Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the parallelogram in a printable form as shown in the sample output. class Rectangle - a subclass of parallelogram (15) Has a single constructor with the 8 values (4 (x,y) pairs) that uses super(...) to create the trapezoid. (Assume two of the sides are parallel to either the x-axis or y-axis.) Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the rectangle in a printable form as shown in the sample output. class Square a subclass of parallelogram (15) Create a toString method which returns a String with the four coordinates pairs as well as the width, height and area of the square in a printable form as shown in the sample output. Use QuadrilateralTest.java to test the program. Download this class from the Programs /Lesson 2/Homework tab Sample Output: Coordinates of quadrilateral are (1.10, 1.20), (6.60, 2.80), (6.20, 9.90), (2.20, 7.40) Coordinates of trapezoid are (0.00, 0.00), (10.00, 0.00), (8.00, 5.00), (3.30, 5.00) Height is: 5.00: Area is 36.75 Coordinates of parallelogram are (5.00, 5.00), (11.00, 5.00), (12.00, 20.00), (6.00, 20.00) Width is 6.00 Height is 15.00 Area is: 90.00 Coordinates of Rectangle are (17.00, 14.00), (30.00, 14.00), (30.00, 28.00), (17.00, 28.00) Width is 13.00 Height is 14.00 Area is: 182.00 Coordinates of square are (4.00, 0.00), (8.00, 0.00), (8.00, 4.00), (4.00, 4.00) Side is 4.00 Area is: 16.00

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