Question: java program The hierarchy has the following classes: - Class TwoDimensionalShape is the superclass of the hierarchy. It has one instance variable shapeName (of type

java program
java program The hierarchy has the following classes: - Class TwoDimensionalShape is
the superclass of the hierarchy. It has one instance variable shapeName (of
type String). It has a constructor that initializes shapeName to the value

The hierarchy has the following classes: - Class TwoDimensionalShape is the superclass of the hierarchy. It has one instance variable shapeName (of type String). It has a constructor that initializes shapeName to the value specified in the parameter. It has one method tostring that returns the string representation of the shape name. - Class Circle is derived from TwoDimensionalShape. It has one instance variable radius (of type double). It has a constructor that calls the super class constructor to initialize the shape name and it initializes the radius to the value specified in the parameter. It has two methods: a method getArea that returns the area of the circle and a method tostring that overrides the superclass version and returns a string representation of the shape name and the area. - Class Rectangle is derived from TwoDimensionalShape. It has two instance variables length and width (both of type double). It has a constructor that calls the super class constructor to initialize the shape name and it initializes the length and width to the values specified in the parameters. It has two methods: a method getArea that returns the area of the rectangle and a method toString that overrides the superclass version and returns a string representation of the shape name and the area. - Class Triangle is derived from TwoDimensionalShape. It has two instance variables base and height (both of type double). it has a constructor that cals the super class constructor to initialize the shape name and it initializes the base and height to the values specified in the parameters. It has two methods: a method getArea that returns the area of the triangle and a method toString that overrides the superclass version and returns a string representation of the shape name and the area. - Write a test class named TwoDimensionalShape Test that has a main method to test your classes. In the main method, prompt the user to input a two-dimensional shape name, the radius of a circle, the length and width of a rectangle and the base and height of a triangle. Create TwoDimensionaiShape, Circle, Rectangle and Triangle objects and initialize the objects with the values entered by the user. Call toString method for each object and print the output. Area formula: Circle Area = radius 2 Rectangle Area = length width Triangle Area =21 base height Sample Output Enter the two-dimensional shape name: 2D shape Enter the radius of the circle: 2 Enter the length of the rectangle: 2 Enter the width of the rectangle: Enter the base of the triangle: Enter the height of the triangle: 8 This is a 2D shape This is a Circle. Its area is 12.57 squared cm This is a Rectangle. Its area is 8.00 squared cm This is a Triangle. Its area is 16.00 squared cm - Class ThreeDimRoundShape is the superclass of the hierarchy. It has one instance variable: radius (of type double). It has a constructor that initializes the radius to the specified value. It has two methods: toString that returns the string representation of the radius, getRadius that returns the value of the radius. - Class Cylinder is derived from ThreeDimRoundShape. It has one instance variable: height (of type double). It has a constructor that calls the superclass constructor to initialize the radius to the specified value and then it initializes height to the specified value. It has three methods: a method getArea that returns the surface area of the cylinder (Surface Area =2rh, wherer is the radius and h is the height), a method getVolume that returns the volume of the cylinder (Volume=r2h, where r is the radius and h is the height), and a method toString that overrides the superclass version and returns the string representation of the radius, height, area and volume. - Class Sphere is derived from ThreeDimRoundShape. It has a constructor that calls the superclass constructor to initialize the radius to the specified value. It has three methods: a method getArea that returns the surface area of the sphere (Surface Area = 4r2, where r is the radius), a method getvolume that returns the volume of the sphere (Volume =34r3, where r is the radius), and a method toString that overrides the superclass version and returns the string representation of the radius, area and volume. - Write a test class named ThreeDimRoundShapeTest that has a main method to test your classes. In the main method, prompt the user to input the information of both shapes. Create ThreeDimRoundShape, Cylinder and Sphere objects and initialize the objects with the values entered by the user. Call tostring method for each object and print the output. Sample Output: Enter the 3D round shape: 5 Enter the radiun of the sphere: 2 Enter the radius of the cylinder: 3 Enter the height of the cylinder: 6 The 3D round shape: Radius =5.00 The Sphere: Radius =2.00 Area =50.27 Volume =33.51 The Cylinder: Radiss =3.00 Height =6.00 Area =113.10 Volune =169.65

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!