Question: Write a class Container that has: instance variables: double height: // the height of the liquid container in centimeters double filledHeight; // the level of

Write a class Container that has:

  1. instance variables:

double height: // the height of the liquid container in centimeters

double filledHeight; // the level of liquid in the container (if it equals height, container is full)

  1. The class should have a constructor.
  2. A method public void fill(double cm) that increases the filled height of a container by the given amount in centimeters. This method will throw OverFillException if we are overfilling the container.
  3. A method public abstract double getBaseArea() that should return the base area of a given container.
  4. A method public double getVolume() to get the volume of the container.

(Note: volume = height * baseArea)

  1. A method public double getFilledVolume() to get the volume of water that is filling the container.

(Note: filled volume = filledHeight * baseArea)

  1. An equals method that compares two Container objects based on their filledVolume.

Write two classes CubicContainer and Cylinder that are subclasses of Container.

The class CubicContainer has:

  1. Instance variables representing width and length of the base.
  2. Calculation of the base area (area = width * length)
  3. Appropriate constructor.

The class Cylinder has:

  1. An instance variable radius, representing radius of the base.
  2. Calculation of the base area (area = 3.14 * radius2)

Appropriate constructor

(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!