Question: Create a class named Square that contains data fields for height, width and surfaceArea, and the methods computerSurfaceArea() and computerPerimeter(). Create a subclass named Cube,

Create a class named Square that contains data fields for height, width and surfaceArea, and the methods computerSurfaceArea() and computerPerimeter().

Create a subclass named Cube, which includes an additional data field named depth as well as the computeSurfaceArea() method that overrides the parents class method with the same name. Add the computeVolume() method which calculates the volume.

In the Square and Cube classes add the overloaded constructors which accept one parameter and create the objects with equal values of height, width for Square and height, width and depth for Cube.

Write a driver class ShowSquareCube, which accepts a users input for a square and cube dimensions, instantiates a Square object, a Cube object and calculates and displays surface area, perimeter and volume relevant to each object. Save the classes as Square.java, Cube.java and ShowSquareCube.java.

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!