Question: Java Program !!!Urgent!!! Thumbs up if done Quadrilateral Inheritance Write an inheritance hierarchy for classes Quadrilateral. Trapezoid. Parallelogram. Rectangle and Square. Use Quadrilateral as the
Java Program !!!Urgent!!! Thumbs up if done





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 (.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 get Height that calculates and returns the height. A method getArea that returns the area of the trapezoid as a double. A method getSum OfTwo Sides that returns a double. Here is this method // return the sum of the trapezoid's two sides public double getSumOfTwo Sides() { if (getPoint10.getY0= getPoint20.getY() { return Math.abs(getPoint 10.getXO - getPoint20.getX()) + Math.abs(getPoint30.getX() - getPoint40.getX(): } else { return Math.abs(getPoint20.getXO - getPoint30.getX() + Math.abs(getPoint40.getXO - 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 getWidth() { if (getPoint10.getY0= 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. | public class QuadrilateralTest { public static void main(String[] args) { // NOTE: All coordinates are assumed to form the proper shapes // 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 equilateral parallelogram Square square = new Square(4.0.0.0, 8.0.0.0, 8.0, 4.0, 4.0, 4.0): System.out.printfi "%s %s %s %s %s ", quadrilateral, trapezoid, parallelogram. rectangle, square): } } 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 (.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 get Height that calculates and returns the height. A method getArea that returns the area of the trapezoid as a double. A method getSum OfTwo Sides that returns a double. Here is this method // return the sum of the trapezoid's two sides public double getSumOfTwo Sides() { if (getPoint10.getY0= getPoint20.getY() { return Math.abs(getPoint 10.getXO - getPoint20.getX()) + Math.abs(getPoint30.getX() - getPoint40.getX(): } else { return Math.abs(getPoint20.getXO - getPoint30.getX() + Math.abs(getPoint40.getXO - 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 getWidth() { if (getPoint10.getY0= 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. | public class QuadrilateralTest { public static void main(String[] args) { // NOTE: All coordinates are assumed to form the proper shapes // 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 equilateral parallelogram Square square = new Square(4.0.0.0, 8.0.0.0, 8.0, 4.0, 4.0, 4.0): System.out.printfi "%s %s %s %s %s ", quadrilateral, trapezoid, parallelogram. rectangle, square): } } 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
Get step-by-step solutions from verified subject matter experts
