Question: Write a class Box that contains instance data: width, height, and depth. Define Boxs constructor to accept and initialize all instance data. Provide the following

Write a class Box that contains instance data: width, height, and depth. Define Boxs constructor to accept and initialize all instance data. Provide the following methods in the class Box:

String toString() //returns one line description of the box as String.

int volume() // returns volume which is product of width, height, and depth.

int surface() //returns surface as 2* (width * height + depth * width + height * depth)

int linearInchSize() //returns sum of depth, width and height.

boolean small() // returrns true if linearInchSize is less than 30 inches, and also each side

// individually is less than 10. Otherwise it returns false.

boolean large() //returns true if linearInchSize is above 100 inches, and false otherwise.

boolean regular() //returns true if box is neither small nor large.

Create a TestBox class with main method in it. Within main method instantiate three Box objects. Provide width, height, and depth in such a way that first box is small, second box is large, and third box is regular. For each box invoke all of the seven methods. Provide appropriate comments to inform user what is the meaning of resulting values.

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!