Question: In java: #1. Create an abstract class named Container that has one integer attribute named size , and one String attribute named color. [8 points]
In java:
#1. Create an abstract class named Container that has one integer attribute named size, and one String attribute named color. [8 points]
- It should have a method called getSize() and getColor() that return the size and color of the container respectively.
- It should also have an abstract method named getVolume() that returns a double.
#2 and #3. Create a child class named Bowl and a child class named Cube. [10 + 10 = 20 points]
The size attribute will refer to the diameter of the bowl and to the side of the cube. (No need to do anything, just understand the significance of the size attribute would imply the diameter and side of the bowl and cube respectively).
(Optional) You may add any attributes or methods to the child classes that are needed.
(Required) Both child classes should at-least have methods as shown below:
- Constructor with parameters
- getVolume()
- equals()
- toString()
#4. Create an application called ContainerTest that will create an array of Container type. Then, create a few (no less than 2) Bowl and Cube objects and have each array element refer to one such object.
Process the array of those Containers in one loop polymorphically by calling the getVolume() method and use it to output to the console their respective volumes.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
