Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 continued (f) Write a height method that gives the height of the liquid in the Cube at any time. Write the unit test

image text in transcribed

Question 1 continued

(f) 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 [4]

(g) Create a constructor so that a new Cube can be instantiated using the state of a current Cube object. [2]

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 flls' the cube with a certain volume of a substance (e.g. a liquid). However, it cannot fill the cube beyond its maximum capacity (e) 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 4 public class Cube f 5 private int width; private int height; private int length; 6 7 8 private int currentVol-0; 1/current volume of liquid in Cube 10 public Cube(int w,int h, int width- W height h Length 1; 12 13 14 15 6/ 17The 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 19 21 23 public int fillint vol 24 25 26 28 29 31 34 35 6 public static void main(String args 37 38 Cube obj1-new Cube(2,3,2); System.out.println(obj1.fil1(2; //output-2 System.out.println(obj1.fil1(3;//output-3 System.out.println(obj1.fill(4)); //output4 System.out.printlnCobj1.fill(12);//output-3 System.out.printinCobj1.fill(z); //output-0 41 43 Question 1 continues on the next page

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago