Question
The program below gives the code for a Cube class. As the main method demonstrates a fill method can be called on the Cube object.
The program below gives the code for a Cube class. As the main method demonstrates a fill method can be called on the Cube object. Each time it is called it fills the cube with a certain volume of a substance (e.g. a liquid). However, it cannot fill the cube beyond its maximum capacity.
- Using the code in the main method below, write a unit test for the fill method. Then implement the fill method. Your answer should include a screen shot of the green or red bar from the unit test.
- Write a height method that gives the height of the liquid in the Cube at any time. Write the unit test to demonstrate that the height method works as expected.
- Create a constructor so that a new Cube can be instantiated using the state of a current Cube object.
4 public class Cube private int width; 6 private int height; 7 private int length; 9 private int currentvol 0; //current volume of liquid in Cube 10e public CubeCint w,int h, int D width W; height = h; length 1; 14 16/ 17 18 The fill method accepts an int value (vol) which indicates a volume of liquid with which to fill the Cube. However, the Cube cannot be filled beyond its maximum capacity. The fill method returns an int value for how much of the input value the Cube has been able to accept. 20 23 public int fillint vol 24 25 26 27 28 31 35 36 public static void main(String args) 37 38 39 1 Cube obj1-new Cube(2,3,2); System.out.println(obj1.fill(2; //output 2 System.out.printIn(obj1.fill(3)); //output 3 System.out.printinobjl.fill(4)); //output = 4 System.out.println(obj1.fill(12));//output 3 System.out.printinobjl.fill(7)); //output = 0 41 43Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started