DrinkInBox is a child of Drink class. It represents a drink in a carton. It has
ID: 3553563 • Letter: D
Question
DrinkInBox is a child of Drink class. It represents a drink in a carton. It has the following attributes:
Attribute name
Attribute type
Description
height
int
The heigt of the box of the drink.
width
int
The width of the box of the drink.
depth
int
The depth of the box of the drink.
The following constructor method should be provided:
public DrinkInBox(String, double, int, int, int)
The height, width, depth are initialized to the value of the third parameter, the fourth parameter, and the fifth parameter, respectively, and the constructor of the parent class Drink should be called using the first and second parameters. Leave volume and totalPrice as their default value.
The following method should be implemented:
public void computeTotalPrice()
First, it computes the volume of the box of the drink. (computed by height*width*depth)
Then compute the total price of the drink. (computed by volume * unitPrice)
Also, the following method should be implemented:
public String toString()
The toString() method inherited from the Drink class should be used to create a new string, and display a box drink's information using the following format:
nTheDrink in a Box
The Height:t 5
The Width: 10
The Depth: 5
The DrinkId: milk515
The Volume: 250
The Unit Price: 0.0055
The Total Price: $1.38
This toString method should make use of the toString method of the parent class.
The DrinkParser class is a utility class that will be used to create a drink object (either a cylinder drink object or a box drink object) from a parsable string. The DrinkParser class object will never be instantiated. It must have the following method:
public static Drink parseStringToDrink(String lineToParse)
The parseStringToDrink method's argument will be a string in the following format:
For a cylinder drink,
shape/drinkId/unitPrice/radius/height
For a box drink,
shape/drinkId/unitPrice/height/width/depth
A real example of this string would be:
Cylinder/soda200/0.0054/5/10
OR
Box/milk03/0.0035/10/15/10
This method will parse this string, pull out the information, create a new DrinkInCylinder or DrinkInBox object using their constructor with attributes of the object, and return it to the calling method. The type will always be present and always be either Cylinder or Box. (It can be lower case or upper case) You may add other methods to the DrinkInCylinder and DrinkInBox class in order to make your life easier.
Attribute name
Attribute type
Description
height
int
The heigt of the box of the drink.
width
int
The width of the box of the drink.
depth
int
The depth of the box of the drink.
Explanation / Answer
Find the code here : http://ideone.com/a8NdKK
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.