Answered step by step
Verified Expert Solution
Question
1 Approved Answer
You must submit both Java files mentioned below along with the output as text files. For this assignment you will create two Java classes each
You must submit both Java files mentioned below along with the output as text files. For this assignment you will create two Java classes each in a separate Java file: 1. The first is the Box class that models a heavy "Box" that should be saved in a file called Box.java. This class should include the following: a. Four private integer instance variables store the Length, Width, Height, and Weight of the Box. Measurements are in feet and pounds. b. Four public methods (setters) to set the value of each of these parameters: setLength, setWidth, setHeight, and set Weight. c. Four public methods (getters) to return the value of each of these parameters: getLength, getWidth, get Height, and get Weight d. Two constructors: Constructor #1 (default constructor) - has no parameters and initializes each of the Box's instance variable to 0. Constructor #2 - that receive four integer parameters that would initialize the Box object's Length, Width, Height, and Weight e. A method calculateVolume( ) which returns the volume (formula: Length*Width*Height) of the Box object as an integer. f. A method calculate Density() which returns the density of the Box (formula: weight/volume) as a double, check for divide by 0. g. A method called toString() that returns all information about a box object as a string in the form of: This Box has: Length = xxx, Width = yyy, Height = zzz, Weight = www Volume = ttt Density = nnn.dd 1. The second is the TestBoxes class that should be saved in a file called TextBoxes.java that contains a main() method. This main() method should do the following: a. Create two different object boxes named bl, and b2 using the second constructor (defined above). The parameters of box bl are: Length = 10, Width =5, Height =5, and Weight = 2600 The parameters of box b2 are: Length = 15, Width =22, Height =16, and Weight = 1360 b. Create a third box named b3 using the default constructor. Then use the set methods (defined above) to assign values for each of the above four parameters as follows: Length = 12, Width = 14, Height =8, and Weight=564243 c. Using the set methods defined above to change the parameters of object b2 to be as follows: Length = 40, Width =11, Height =18, and Weight = 224321 d. Output all information of each of the three created object boxes (b1,b2, and b3) using the method toString() on the screen. Just Compile the Box.java class (you cannot run it, there is no main method) in this class. Compile and run the TestBoxes class. Output: This Box has: Length = 10, Width = 5, Height = 5, Weight = 2600 Volume = 250 Density = 10.4 This Box has: Length = 40, Width = 11, Height = 18, Weight = 224321. Volume = 7920 Density = 28.32 This Box has: Length = 12, Width = 14, Height = 8, Weight = 564243. Volume = 1344 Density = 419.82
Step 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