Question: The following Rectangle class is used to represent a rectangle. Each Rectangle object has attributes for the length and width. public class Rectangle { private

The following Rectangle class is used to represent a rectangle. Each Rectangle object has attributes for the length and width.

public class Rectangle { private int length; private int width; public Rectangle(int len, int wid) { length = len; width = wid; } public int getLength() { return length; } public int getWidth() { return width; } public int calculateArea() { return length * width; } public String toString() { return Length: length + Width: + width; } } The following Rectangle class is used to represent a rectangle. Each Rectangle

The RectangularPrism is a subclass of the Rectangle class that has one additional attribute: an int variable named height that is used to represent the height of the prism. The RectangularPrism class also contains a calculateVolume method to calculate the volume of a rectangular prism (volume = length * width * height) and a toString method. Consider the following code segments and printed results: Code Segment Result Printed Rectangular Prism rp = new RectanglularPrism (3, 4, 10); System.out.println(rp); Length: 3 Width: 4 Height: 10 System.out.println("Volume: + rp.calculateVolume()); Volume: 120 (a) Complete the RectangularPrism class. Your implementation should conform to the example above AND include necessary accessor & mutator methods. /* Write your answer on the next page in the space provided */ The Cube class is a subclass of RectangularPrism that represents a three-dimensional square. The Cube class does not contain any attributes or methods other than those found in the RectangularPrism class. Code Segment Result Printed Cube myCube = new Cube (5); System.out.println (myCube); Length: 5 Width: 5 Height: 5 System.out.println("Volume: + cube.calculateVolume()); Volume: 125 (b) Write the complete Cube class. Your implementation must meet all specifications and conform to the behavior shown in the table

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!