We Pack N Ship 4 U packs and ships items using two kinds of

We Pack N Ship 4 U packs and ships items using two kinds of containers: boxes and mailing tubes (cylinders). Rates are determined by the size of the container. The size of a box is the sum of its three dimensions: length, width, and depth, in inches. For a mailing tube, with radius r inches and length I, size is calculated as 2nr 1. The cost of packing and shipping a box is $0.35 times the size of the cube. For a tube the cost is $0.25 times the size of the container Define an abstract class Container with a single instance variable, double length, two abstract methods double getsize) and double getCost(), and one getter method double getLength) Container should also implement Comparable based on cost. Next, create two subclasses of Container, Box and Tube, that implement getCost) and getSize(), where getCost() returns the cost of packing and shipping and getSize) returns the size of a container, as previously described. Box needs additional instance variables width and depth, and Tube requires radius. Include getter methods for Box and Tube Finally, implement a TestContainer class that accepts 10 Container objects and stores them in an array. For each container, TestContainer should ask whether the container is a box or a tube and prompt for the appropriate dimensions Sort the 10 containers in ascending order by cost. Print the type of container, the dimensions of the container, and the cost, rounded to two decimal places. Hint: If x is an object, then x.getClass().getName() returns the name of the class (a String reference) to which x belongs.

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

---------------------------------

OUTPUT:

Container is: box or tube?
box
Enter length:
2
Enter width:
4
Enter depth:
2
Container is: box or tube?
tube
Enter length:
3
Enter radius:
6
Container is: box or tube?
2
Invalid option! Try again..
Container is: box or tube?
box
Enter length:
3
Enter width:
6
Enter depth:
2
Container is: box or tube?
box
Enter length:
6
Enter width:
8
Enter depth:
2
Container is: box or tube?
tube
Enter length:
1
Enter radius:
4
Container is: box or tube?
tube
Enter length:
4
Enter radius:
1
Container is: box or tube?
tube
Enter length:
5
Enter radius:
2
Container is: box or tube?
box
Enter length:
6
Enter width:
2
Enter depth:
6
Container is: box or tube?
box
Enter length:
4
Enter width:
6
Enter depth:
8
Container is: box or tube?
tube
Enter length:
1
Enter radius:
4
Type of container: com.sabre.airmax.gui.Box
Dimensions: [width=4.0, depth=2.0length=2.0]
Cost: 2.8
Type of container: com.sabre.airmax.gui.Box
Dimensions: [width=6.0, depth=2.0length=3.0]
Cost: 3.85
Type of container: com.sabre.airmax.gui.Box
Dimensions: [width=2.0, depth=6.0length=6.0]
Cost: 4.9
Type of container: com.sabre.airmax.gui.Box
Dimensions: [width=8.0, depth=2.0length=6.0]
Cost: 5.6
Type of container: com.sabre.airmax.gui.Tube
Dimensions: [radius=4.0length=1.0]
Cost: 6.28
Type of container: com.sabre.airmax.gui.Tube
Dimensions: [radius=1.0length=4.0]
Cost: 6.28
Type of container: com.sabre.airmax.gui.Tube
Dimensions: [radius=4.0length=1.0]
Cost: 6.28
Type of container: com.sabre.airmax.gui.Box
Dimensions: [width=6.0, depth=8.0length=4.0]
Cost: 6.3
Type of container: com.sabre.airmax.gui.Tube
Dimensions: [radius=2.0length=5.0]
Cost: 15.7
Type of container: com.sabre.airmax.gui.Tube
Dimensions: [radius=6.0length=3.0]
Cost: 28.26

 We Pack N Ship 4 U packs and ships items using two kinds of containers: boxes and mailing tubes (cylinders). Rates are determined by the size of the container.
 We Pack N Ship 4 U packs and ships items using two kinds of containers: boxes and mailing tubes (cylinders). Rates are determined by the size of the container.
 We Pack N Ship 4 U packs and ships items using two kinds of containers: boxes and mailing tubes (cylinders). Rates are determined by the size of the container.

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site