Instructions

Create a class named Box that includes integer data fields for length, width and height. Create three constructors that require one, two and three arguments, respectively. Code the constructors as follows:

  • The constructor that takes one argument should assign the value to length and assign zeros to height and width. This constructor should also print a line of text that says, "Line created with length XX". Be sure to replace the 'XXX' with the value of length using the Java keyword this in your code.
  • The constructor that takes two arguments should assign the first value to length, the second to width and zero to height. This constructor should also print a line of text that says, "Rectangle created with length XXX and width XXX". Be sure to replace the 'XXX' with the values of length and width using the Java keyword this in your code.
  • The constructor that takes three arguments should assign the first value to length, the second to width and the third to height. This constructor should also print a line of text that says, "Box created with length XXX, width XXX, and height XXX". Be sure to replace the 'XXX' with the values of length, width and height using the Java keyword this in your code.

When you are finished writing this class, write a second class called BoxTest that tests each of the constructors and demonstrates that each works correctly. You may use any values for length, width and height in your program or you can prompt the user to enter these values.

Although the output of your program is not required to look this way, it might look something like:

Line created with length 5.
Rectangle created with length 10 and width 15.
Box created with length 1, width 2, and height 3.

Once your program works correctly, be sure to submit both the Box.java and BoxText.java files for grading.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.