Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in java coding Create a new class named BoxDriver in the com.lg.exercises package. Ensure that this class has a main() method defined. In the main

in java coding
image text in transcribed
image text in transcribed
Create a new class named BoxDriver in the com.lg.exercises package. Ensure that this class has a main() method defined. In the main method of BoxDriver, create two Box objects using the keyword new a. A box named box1 with a length of 5, a width of 6 and a height of 7 b. A box named box2 where all three sides are 10 Using the get methods, print out the value for each attribute of both boxes. Ensure that the attributes were set correctly by the Box constructors. Execute the main method for BoxDriver. The output should be like the following. If there are any errors in your Box code at this point, correct them and re-run the test. Box 1 length is + 5.0 Box 1 width is + 6.0 Box 1 height is + 7.0 Box 2 length is + 10.0 Box 2 width is + 10.0 Box 2 height is + 10.0 Ensure that your set methods work correctly. Call each set method for box1 changing the values to the following and then use the get methods to ensure that the attributes were set correctly. a. Length = 3 b. Width = 4 C. Height = 5 Call the getVolume () and get SurfaceArea () methods on boxi and ensure they are functioning correctly. If not, fix the code and re-test. Execute the printBox() for box1. Ensure that it is functioning correctly. If not, fix the code and re-test. Using the setLength() method, change the length of box1 to -5. Execute the printBox() method again. What happens? You should receive a message stating that the box contains invalid attributes. In order to avoid setting attributes to invalid values, re-code the set methods of the Box class to only accept values greater than 0. If a value less than or equal to zero is detected, print an error message like the following: System.out.println("Length must be greater than 0")

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

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions