assingment # 5
Project ID: 1265690267
Project Details
- Status: Closed (Chosen Programmer: areca; Paid; Rated 10 out of 10)
- Posted: 2/8/2010 at 23:37 EST
- Closed: 2/9/2010 at 15:41 EST
- Project Creator:
- Budget: $10-25
- Description: CSE 205 - Assignment #5
Due Date: Friday, February 19th by 8:00PM
Minimal Submitted Files
You are required, but not limited, to turn in the following source files:
Assignment5.java (Download this file and use it as your driver program for this assignment. You need to add more code to complete it.)
Drink.java
DrinkInBox.java
DrinkInCylinder.java
DrinkParser.java
Requirements to get full credits in Documentation
The assignment number, your name, StudentID, Lecture time, and a class description need to be included at the top of each class/file.
A description of each method is also needed.
Some additional comments inside of methods to explain code that are hard to follow
Skills to be Applied
In addition to what has been covered in previous assignments, the use of the following items, discussed in class, will probably be needed:
Inheritance
The protected modifier
The super Reference
Abstract class
NumberFormat
ArrayList
Program Description
Class Diagram (download the .ppt file of the figure):
In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for drinks to sell.
Drink class
Drink is an abstract class, which represents the basic attributes of any drink in a container. It is used as parent of the drink hierarchy. It has the following attributes (should be protected):
Attribute name
Attribute type
Description
volume
int
The volume of the drink
unitPrice
double
The price per unit of the drink
totalPrice
double
The total price of the drink
drinkId
String
The Id of the drink
The following constructor method should be provided to initialize the instance variables.
public Drink(String, double)
The instance variable volume is initialized to 0, totalPrice is initialized to 0.0, unitPrice is initialized to the value of the second parameter, and drinkId is initialized to the string value of the first parameter.
The following accessor method should be provided to get the drinkId :
public String getDrinkId()
The class Drink also has an abstract method (which should be implemented by its child classes, DrinkInCylinder and DrinkInBox) to compute the volume of the drink:
public abstract void computeTotalPrice();
The following public method should be provided:
public String toString()
toString method returns a string of the following format:
\nThe DrinkId:\t\t10001\n
The Volume:\t\t150\n
The Unit Price:\t\t0.0015\n
The Total Price:\t$330.00\n\n
DrinkInCylinder class
DrinkInCylinder is a subclass of Drink class. It represents a drink in a can (cylinder). It has the following attribute in addition to the inherited ones:
Attribute name
Attribute type
Description
radius
int
The radius of the cylinder of the drink.
height
int
The height of the cylinder of the drink.
The following constructor method should be provided:
public DrinkInCylinder(String, double, int, int)
The radius is initialized to the value of the third parameter, the height is initialized to the value of the fourth parameter, 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 for the cylinder of the drink. (computed by PI*(radius*radius*height), the constant value PI is defined in the Math class. -- (int) (Math.PI*(radius*radius*height)) Also, compute (radius*radius*height) first since they are all integers. PI is a float point number, so you need to cast the final value to an integer ("volume" is an integer.) 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 Drink class should be used to create a new string, and display a cylinder drink's information using the following format:
\nThe Drink in a Cylinder\n
The Radius:\t\t5\n
The Height:\t\t10\n
The DrinkId:\t\tsona200\n
The Volume:\t\t785\n
The Unit Price:\t\t0.0022\n
The Total Price:\t$1.73\n\n
This toString method should make use of the toString method of the parent class.
DrinkInBox class
DrinkInBox is a subclass 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:
\nThe Drink in a Box\n
The Height:\t\t5\n
The Width:\t\t10\n
The Depth:\t\t5\n
The DrinkId:\t\tmilk515\n
The Volume:\t\t250\n
The Unit Price:\t\t0.0055\n
The Total Price:\t$1.38\n\n
This toString method should make use of the toString method of the parent class.
DrinkParser 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 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.
Assignment5 class
In this assignment, download Assignment5.java file by clicking the link, and use it for your assignment. You need to add code to this file. The parts you need to add are written in the Assignment5.java file, namely for the four cases "Add Drink", "Add Compute Total Prices", "Search for Drink", and "List Drinks".
All input and output should be handled here. The main method should start by displaying this updated menu in this exact format:
Choice\t\tAction\n
------\t\t------\n
A\t\tAdd Drink\n
C\t\tCompute Total Prices\n
D\t\tSearch for Drink\n
L\t\tList Drinks\n
Q\t\tQuit\n
?\t\tDisplay Help\n\n
Next, the following prompt should be displayed:
What action would you like to perform?\n
Read in the user input and execute the appropriate command. After the execution of each command, redisplay the prompt. Commands should be accepted in both lowercase and uppercase.
Add Drink
Your program should display the following prompt:
Please enter a drink information to add:\n
Read in the information and parse it using the drink parser.
Then add the new drink object (created by drink parser) to the drink list.
Compute Total Prices
Your program should compute total price for all drinks created so far by calling computeTotalPrice method for each of them in the drink list.
After computing total prices, display the following:
total prices computed\n
Search for Drink
Your program should display the following prompt:
Please enter a drinkID to search:\n
Read in the string and look up the drink list, if there exists a drink object with the same drink ID, then display the following:
drink found\n
Otherwise, display this:
drink not found\n
List Drinks
List all drinks in the drink list. Make use of toString method defined in DrinkInBox and DrinkInCylinder classes.
A real example is looked like this:
The Drink in a Cylinder
The Radius: 5
The Height: 10
The DrinkId: soda200
The Volume: 785
The Unit Price: 0.0054
The Total Price: $4.24
The Drink in a Box
The Height: 10
The Width: 15
The Depth: 10
The DrinkId: milk03
The Volume: 1500
The Unit Price: 0.0035
The Total Price: $5.25
If there is no drink in the drink list (the list is empty), then display following:
no drink\n
Quit
Your program should stop executing and output nothing.
Display Help
Your program should redisplay the "choice action" menu.
Invalid Command
If an invalid command is entered, display the following line:
Unknown action\n
Test cases:
Input
The following files are the test cases that will be used as input for your program (Right-click and use "Save As"):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
Output
The following files are the expected outputs of the corresponding input files from the previous section (Right-click and use "Save As"):
Test Case #1
Test Case #2
Test Case #3
Test Case #4
Error Handling
Your program is expected to be robust to pass all test cases. - Tags:
| Project Bids |
| Programmer | Bid |
Delivery Time | Time of Bid | Rating | |
| ik10 | $10 | 1 day | 2/9/2010 at 4:30 EST | (No Feedback Yet) | |
| I will do this... | |||||
| justgig8 | $15 | 3 hours | 2/9/2010 at 4:59 EST | (No Feedback Yet) | |
| I maybe considered for I have a lot of experience of completing projects for students. Presentation as well will be of utmost satisfaction level. | |||||
| areca | $20 | 1 day | 2/9/2010 at 14:36 EST | (112 reviews) |
|
| Hi, Please see PM, Regards | |||||
| gypsicoder | $20 | 1 day | 2/9/2010 at 13:02 EST | (104 reviews) |
|
| Can give you the codes within 1 day. | |||||
| puimic | $20 | 1 day | 2/9/2010 at 13:47 EST | (29 reviews) |
|
| Quality work. Proven experience. | |||||
| lostzac | $20 | 1 day | 2/9/2010 at 7:31 EST | (1 review) |
|
| I have tutored in Java and would be happy to do this for you. Every assignment I have helped with has received an A | |||||
| esconpk | $20 | 5 days | 2/9/2010 at 3:48 EST | (No Feedback Yet) | |
| Please see pmb... Regards... | |||||
| sanboe1430 | $20 | 7 days | 2/9/2010 at 10:46 EST | (No Feedback Yet) | |
| Hi, I have a company .But I still like coding as a developer.I am interested to do this work .check my website for details.And On going projects. Hope to here from you soon.Take care. | |||||
| atrigen | $24 | 5 hours | 2/9/2010 at 4:06 EST | (46 reviews) |
|
| Simple to implement, check my reviews for similar projects. | |||||
| eperfections |
$25 | Immediately | 2/9/2010 at 0:15 EST | (292 reviews) |
|
| Please see PMB | |||||
| medsquad | $25 | Immediately | 2/9/2010 at 5:35 EST | (11 reviews) |
|
| Greetings, Ready to start this work. Please check PMB, portfolio & Reviews Thanks Medsquad | |||||
| aleksandr85 | $25 | 3 days | 2/9/2010 at 11:05 EST | (3 reviews) |
|
| Hello! I'm interested working with you on this project. Regards, Alexander. | |||||






