SlideShare a Scribd company logo
1 of 15
Download to read offline
Here is the assignment5.java file :-
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 codes to complete it.)
Soup.java
SoupInBox.java
SoupInCylinder.java
SoupParser.java
Requirements to get full credits in Documentation
The assignment number, your name, StudentID, Lecture number/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 (especially for a "main" method) to explain code
that are hard to follow should be written.
You can look at Java programs in the text book to see how comments are added to programs.
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/DecimalFormat
Wrapper classes
ArrayList
Program Description
Class Diagram:
In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for
vehicles.
Soup is an abstract class, which represents the basic attributes of any soup in a container to be
sold. It is used as the root of the soup hierarchy. It has the following attributes (should be
protected):
Attribute name
Attribute type
Description
volume
int
The volume of the soup
unitPrice
double
The price per unit of the soup
totalPrice
double
The total price of the soup
soupId
String
The Id of the soup
The following constructor method should be provided to initialize the instance variables.
publicSoup(String id, double someUnitPrice)
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 soupId is initialized to the string value of the
first parameter.
The following accessor method should be provided for soupId :
publicString getSoupId()
The Class Soup also has an abstract method (which should be implemented by its child classes,
SoupInCylinder and SoupInBox) to compute the volume of the soup:
publicabstract void computeTotalPrice();
The following public method should be provided:
publicString toString()
toString method returns a string of the following format:
 The SoupId:tttomatosoup591
The Volume:tt150
The Unit Price:tt0.0015
The Total Price:t$330.00 
You should make use of the NumberFormat class and DecimalFormat (in java.text package) to
format the total price in the dollar format (NumberFormat) and the unit price using 4 digits after
their decimal point (DecimalFormat using "0.0000").
SoupInCylinder class
SoupInCylinder is a subclass of Soup class. It represents a soup 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 soup.
height
int
The height of the cylinder of the soup.
The following constructor method should be provided:
publicSoupInCylinder(String id, double someUnitPrice, int someRadius, int someHeight)
The radius is initialized to the value of the third parameter, the height is initialized to the value of
the forth parameter, and the constructor of the parent class Soup should be called using the first
and second parameters. Leave volume and totalPrice as their default values (defined in the
parent’s constructor).
The following method should be implemented:
publicvoid computeTotalPrice()
First, it computes the volume for the cylinder of the soup. (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 soup. (computed by volume * unitPrice)
Also, the following method should be implemented:
publicString toString()
The toString() method inherited from Soup class should be used to create a new string, and
display a cylinder soup's information using the following format:
 TheSoup in a Cylinder
The Radius:tt5
The Height:tt10
The SoupId:tttomatosoup591
The Volume:tt785
The Unit Price:tt0.0022
The Total Price:t$1.73
This toString method should make use of the toString method of the parent class.
SoupInBox class
SoupInBox is a subclass of Soup class. It represents a soup in a carton. It has the following
attributes:
Attribute name
Attribute type
Description
height
int
The height of the box of the soup.
width
int
The width of the box of the soup.
depth
int
The depth of the box of the soup.
The following constructor method should be provided:
publicSoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int
someDepth)
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 Soup should be
called using the first and second parameters. Leave volume and totalPrice as their default value.
The following method should be implemented:
publicvoid computeTotalPrice()
First, it computes the volume of the box of the soup. (computed by height*width*depth)
Then compute the total price of the soup. (computed by volume * unitPrice)
Also, the following method should be implemented:
publicString toString()
The toString() method inherited from the Soup class should be used to create a new string, and
display a box soup's information using the following format:
 TheSoup in a Box
The Height:tt5
The Width:tt10
The Depth:tt5
The SoupId:ttsplitPeaSoup515
The Volume:tt250
The Unit Price:tt0.0055
The Total Price:t$1.38 
This toString method should make use of the toString method of the parent class.
SoupParser class
The SoupParser class is a utility class that will be used to create a soup object (either a cylinder
soup object or a box soup object) from a parsable string. The SoupParser class object will never
be instantiated. It must have the following method:
publicstatic Soup parseStringToSoup(String lineToParse)
The parseStringToSoup method's argument will be a string in the following format:
For a cylinder soup,
shape/soupId/unitPrice/radius/height
For a box soup,
shape/soupId/unitPrice/height/width/depth
A real example of this string would be:
Cylinder/tomateSoup514/0.0054/5/10
OR
Box/splitPeaSoup7192/0.0035/10/15/10
This method will parse this string, pull out the information, create a new SoupInCylinder or
SoupInBox 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 SoupInCylinder and SoupInBox 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 Soup", "Add Compute Total Prices",
"Search for Soup", and "List Soups".
All input and output should be handled here. The main method should start by displaying this
updated menu in this exact format:
ChoicettAction
------tt------
AttAdd Soup
CttCompute Total Prices
DttSearch for Soup
LttList Soups
QttQuit
?ttDisplay Help 
Next, the following prompt should be displayed:
What action would you like to perform?
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 Soup
Your program should display the following prompt:
Please enter a soup information to add:
Read in the information and parse it using the soup parser.
Then add the new soup object (created by soup parser) to the soup list.
Compute Total Prices
Your program should compute total price for all soups created so far by calling
computeTotalPrice method for each of them in the soup list.
After computing total prices, display the following:
totalprices computed
Search for Soup
Your program should display the following prompt:
Please enter a soupId to search:
Read in the string and look up the soup list, if there exists a soup object with the same soup ID,
then display the following:
soupfound
Otherwise, display this:
soupnot found
List Soups
List all soups in the soup list. Make use of toString method defined in SoupInBox and
SoupInCylinder classes.
A real example is looked like this:
The Soup in a Cylinder Container
The Radius: 5
The Height: 10
The SoupId: chickensoup200
The Volume: 0
The Unit Price: 0.0054
The Total Price: $0.00
The Soup in a Box Container
The Height: 10
The Width: 15
The Depth: 10
The SoupId: tomatosoup03
The Volume: 0
The Unit Price: 0.0035
The Total Price: $0.00
If there is no soup in the soup list (the list is empty), then display following:
nosoup
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
Attribute name
Attribute type
Description
volume
int
The volume of the soup
unitPrice
double
The price per unit of the soup
totalPrice
double
The total price of the soup
soupId
String
The Id of the soup SoupParser parseString ToSoup(lineToParse String): Soup Arizona State
University, CSE205 Spring 2017, Assignment5 Assi nment +main(StringU): void +print
Menu0:void Souplncylinder radius :int -height: int +Souplncylinder(String,double,int,int)
ttoString0: String Sou #volume int 0 #unit Price:double #total Price: double 0.0 #soupld: String
Soup (String,double) tgetSoupld0: String +toString(): String compute Total Price() void
SouplnBox ght: int -width: int -depth: int tSoupInBox (String, nt ttoString0:String
Solution
PROGRAM CODE:
Soup.java
package soup;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public abstract class Soup {
protected int volume;
protected double unitPrice;
protected double totalPrice;
protected String soupId;
Soup(String soupId, double unitPrice)
{
this.soupId = soupId;
this.unitPrice = unitPrice;
this.volume = 0;
this.totalPrice = 0.0;
}
public String getSoupId()
{
return this.soupId;
}
@Override
public String toString() {
String unitPriceFormat = "#.####";
String totalPriceFormat = "$###.##";
NumberFormat UPFormat = new DecimalFormat(unitPriceFormat);
NumberFormat TPFormat = new DecimalFormat(totalPriceFormat);
return " The SoupId:tt" + this.soupId+ " The Volume:tt" + this.volume + " The
Unit Price:tt" +
UPFormat.format(unitPrice) + " The Total Price:t" + TPFormat.format(this.totalPrice) +
"  ";
}
public abstract void computeTotalPrice();
}
SoupInBox.java
package soup;
public class SoupInBox extends Soup{
private int height;
private int width;
private int depth;
public SoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int
someDepth) {
super(id, someUnitPrice);
this.height = someHeight;
this.width = someWidth;
this.depth = someDepth;
}
@Override
public void computeTotalPrice() {
volume = height * width * depth;
totalPrice = volume * unitPrice;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return " The Soup in a Box The Height:tt" + height + " The Width:tt" + width +
" The Depth:tt" + depth + super.toString();
}
}
SoupInCylinder.java
package soup;
public class SoupInCylinder extends Soup{
private int radius;
private int height;
public SoupInCylinder(String id, double someUnitPrice, int someRadius, int someHeight)
{
super(id, someUnitPrice);
this.radius = someRadius;
this.height = someHeight;
}
@Override
public void computeTotalPrice() {
volume = (int) (Math.PI*(radius*radius*height));
totalPrice = volume * unitPrice;
}
@Override
public String toString() {
// TODO Auto-generated method stub
return " The Soup in a Cylinder "+ "The Radius:tt" + this.radius + " The
Height:tt" + height
+ super.toString();
}
}
SoupParser.java
package soup;
public class SoupParser {
public static Soup parseStringToSoup(String lineToParse)
{
String[] input = lineToParse.split("/");
if(input[0].toLowerCase().equals("cylinder"))
{
return new SoupInCylinder(input[1], Double.valueOf(input[2]), Integer.valueOf(input[3]),
Integer.valueOf(input[4]));
}
else
return new SoupInBox(input[1], Double.valueOf(input[2]), Integer.valueOf(input[3]),
Integer.valueOf(input[4]), Integer.valueOf(input[5]));
}
}
Assignment5.java
package soup;
// Assignment #: 5
//Arizona State University - CSE205
// Name: Your name
// StudentID: Your id
// Lecture: Your lecture time (for instance, MWF 10:40am)
//Description: The Assignment 5 class displays a menu of choices
// (add cylinder soup, box soup,search soup,
// list soups, quit, display menu) to a user
// and performs the chosen task. It will keep asking a user to
// enter the next choice until the choice of 'Q' (Quit) is
// entered.
import java.io.*; //to use InputStreamReader and BufferedReader
import java.util.*; //to use ArrayList
public class Assignment5
{
public static void main (String[] args)
{
char input1;
String inputInfo = new String();
String line = new String();
boolean operation;
// ArrayList object is used to store soup objects
ArrayList soupList = new ArrayList();
try
{
printMenu(); // print out menu
// create a BufferedReader object to read input from a keyboard
InputStreamReader isr = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (isr);
do
{
System.out.println("What action would you like to perform?");
line = stdin.readLine().trim();
input1 = line.charAt(0);
input1 = Character.toUpperCase(input1);
if (line.length() == 1)
{
switch (input1)
{
case 'A': //Add Soup
System.out.print("Please enter some soup information to add: ");
inputInfo = stdin.readLine().trim();
Soup soup = SoupParser.parseStringToSoup(inputInfo);
soupList.add(soup);
break;
case 'C': //Compute Total Prices
for(Soup tempSoup: soupList)
tempSoup.computeTotalPrice();
System.out.print("total prices computed ");
break;
case 'D': //Search for Soup
System.out.print("Please enter a soupID to search: ");
inputInfo = stdin.readLine().trim();
operation = false;
for(Soup tempSoup: soupList)
{
if(tempSoup.getSoupId().equals(inputInfo))
{
operation = true;
break;
}
}
if (operation == true)
System.out.print("soup found ");
else
System.out.print("soup not found ");
break;
case 'L': //List Soups
for(Soup tempSoup: soupList)
System.out.println(tempSoup);
break;
case 'Q': //Quit
break;
case '?': //Display Menu
printMenu();
break;
default:
System.out.print("Unknown action ");
break;
}
}
else
{
System.out.print("Unknown action ");
}
} while (input1 != 'Q'); // stop the loop when Q is read
}
catch (IOException exception)
{
System.out.println("IO Exception");
}
}
/** The method printMenu displays the menu to a use **/
public static void printMenu()
{
System.out.print("ChoicettAction " +
"------tt------ " +
"AttAdd Soup " +
"CttCompute Total Prices " +
"DttSearch for Soup " +
"LttList Soups " +
"QttQuit " +
"?ttDisplay Help  ");
}
}
OUTPUT:
Choice Action
------ ------
A Add Soup
C Compute Total Prices
D Search for Soup
L List Soups
Q Quit
? Display Help
What action would you like to perform?
A
Please enter some soup information to add:
Cylinder/tomateSoup514/0.0054/5/10
What action would you like to perform?
A
Please enter some soup information to add:
Box/splitPeaSoup7192/0.0035/10/15/10
What action would you like to perform?
C
total prices computed
What action would you like to perform?
D
Please enter a soupID to search:
splitPeaSoup7192
soup found
What action would you like to perform?
L
The Soup in a Cylinder
The Radius: 5
The Height: 10
The SoupId: tomateSoup514
The Volume: 785
The Unit Price: 0.0054
The Total Price: $4.24
The Soup in a Box
The Height: 10
The Width: 15
The Depth: 10
The SoupId: splitPeaSoup7192
The Volume: 1500
The Unit Price: 0.0035
The Total Price: $5.25
What action would you like to perform?
Q

More Related Content

Similar to Here is the assignment5.java file -You are required, but not limi.pdf

Modeling separation systems_with_aspen_plus
Modeling separation systems_with_aspen_plusModeling separation systems_with_aspen_plus
Modeling separation systems_with_aspen_plusTecna
 
Write a Temperature class that represents temperatures in degrees in .docx
 Write a Temperature class that represents temperatures in degrees in .docx Write a Temperature class that represents temperatures in degrees in .docx
Write a Temperature class that represents temperatures in degrees in .docxajoy21
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentzjkdg986
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentsdfgsdg36
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignmentfdjfjfy4498
 
Can someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfCan someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfarrowvisionoptics
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxjosephineboon366
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com donaldzs157
 
Business App Programming Course Project
Business App Programming Course ProjectBusiness App Programming Course Project
Business App Programming Course ProjectCarmen Lampkin
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdfarkurkuri
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxalfred4lewis58146
 

Similar to Here is the assignment5.java file -You are required, but not limi.pdf (20)

Hw5
Hw5Hw5
Hw5
 
Savitch ch 04
Savitch ch 04Savitch ch 04
Savitch ch 04
 
Modeling separation systems_with_aspen_plus
Modeling separation systems_with_aspen_plusModeling separation systems_with_aspen_plus
Modeling separation systems_with_aspen_plus
 
Write a Temperature class that represents temperatures in degrees in .docx
 Write a Temperature class that represents temperatures in degrees in .docx Write a Temperature class that represents temperatures in degrees in .docx
Write a Temperature class that represents temperatures in degrees in .docx
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
Cmis 212 module 2 assignment
Cmis 212 module 2 assignmentCmis 212 module 2 assignment
Cmis 212 module 2 assignment
 
03b loops
03b   loops03b   loops
03b loops
 
A07
A07A07
A07
 
Can someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdfCan someoen help me to write c++ program including C++ inheritance, .pdf
Can someoen help me to write c++ program including C++ inheritance, .pdf
 
Lab5
Lab5Lab5
Lab5
 
Unit iii
Unit iiiUnit iii
Unit iii
 
Goals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docxGoals1)Be able to work with individual bits in java.2).docx
Goals1)Be able to work with individual bits in java.2).docx
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
 
Business App Programming Course Project
Business App Programming Course ProjectBusiness App Programming Course Project
Business App Programming Course Project
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
READ BEFORE YOU START You are given a partially completed pr.pdf
READ BEFORE YOU START  You are given a partially completed pr.pdfREAD BEFORE YOU START  You are given a partially completed pr.pdf
READ BEFORE YOU START You are given a partially completed pr.pdf
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
OverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docxOverviewUsing the C-struct feature, design, implement and .docx
OverviewUsing the C-struct feature, design, implement and .docx
 

More from mallik3000

Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfExplain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfmallik3000
 
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfExercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfmallik3000
 
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfestion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfmallik3000
 
Discuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfDiscuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfmallik3000
 
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfDiels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfmallik3000
 
Create a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfCreate a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfmallik3000
 
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfCompare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfmallik3000
 
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfChoose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfmallik3000
 
Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfmallik3000
 
Canon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfCanon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfmallik3000
 
Can someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfCan someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfmallik3000
 
Write a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfWrite a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfmallik3000
 
What happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfWhat happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfmallik3000
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfmallik3000
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfmallik3000
 
Why are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfWhy are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfmallik3000
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfmallik3000
 
What is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfWhat is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfmallik3000
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfmallik3000
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfmallik3000
 

More from mallik3000 (20)

Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdfExplain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
Explain how The Capitol Building (in D.C.) is a reflection of Greco-.pdf
 
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdfExercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
Exercise 14-3GURLEY CORPORATION Comparative Condensed Balance Sh.pdf
 
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdfestion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
estion 5 of 34 Sapling Learning Which is the correct name of the fo.pdf
 
Discuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdfDiscuss the difference between the two levels of moral development. .pdf
Discuss the difference between the two levels of moral development. .pdf
 
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdfDiels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
Diels-Alder Post-lab questions F17. 1) Why do the methylene protons.pdf
 
Create a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdfCreate a Balance Sheet to record the following transactions for Tayl.pdf
Create a Balance Sheet to record the following transactions for Tayl.pdf
 
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdfCompare Plato and Aristotles philosophies of mathematics and relat.pdf
Compare Plato and Aristotles philosophies of mathematics and relat.pdf
 
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdfChoose one of the evolutions of Critical Incident Technique (CIT) an.pdf
Choose one of the evolutions of Critical Incident Technique (CIT) an.pdf
 
Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdf
 
Canon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfCanon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdf
 
Can someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfCan someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdf
 
Write a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdfWrite a program that finds the max binary tree height. (This is an ex.pdf
Write a program that finds the max binary tree height. (This is an ex.pdf
 
What happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfWhat happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdf
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Why are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfWhy are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdf
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdf
 
What is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfWhat is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdf
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdf
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdf
 

Recently uploaded

How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxCeline George
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project researchCaitlinCummins3
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsISCOPE Publication
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...EADTU
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...Gary Wood
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnershipsexpandedwebsite
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 

Recently uploaded (20)

How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Scopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS PublicationsScopus Indexed Journals 2024 - ISCOPUS Publications
Scopus Indexed Journals 2024 - ISCOPUS Publications
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 

Here is the assignment5.java file -You are required, but not limi.pdf

  • 1. Here is the assignment5.java file :- 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 codes to complete it.) Soup.java SoupInBox.java SoupInCylinder.java SoupParser.java Requirements to get full credits in Documentation The assignment number, your name, StudentID, Lecture number/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 (especially for a "main" method) to explain code that are hard to follow should be written. You can look at Java programs in the text book to see how comments are added to programs. 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/DecimalFormat Wrapper classes ArrayList Program Description Class Diagram: In Assignment #5, you will need to make use of inheritance by creating a class hierarchy for vehicles. Soup is an abstract class, which represents the basic attributes of any soup in a container to be sold. It is used as the root of the soup hierarchy. It has the following attributes (should be protected): Attribute name Attribute type
  • 2. Description volume int The volume of the soup unitPrice double The price per unit of the soup totalPrice double The total price of the soup soupId String The Id of the soup The following constructor method should be provided to initialize the instance variables. publicSoup(String id, double someUnitPrice) 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 soupId is initialized to the string value of the first parameter. The following accessor method should be provided for soupId : publicString getSoupId() The Class Soup also has an abstract method (which should be implemented by its child classes, SoupInCylinder and SoupInBox) to compute the volume of the soup: publicabstract void computeTotalPrice(); The following public method should be provided: publicString toString() toString method returns a string of the following format: The SoupId:tttomatosoup591 The Volume:tt150 The Unit Price:tt0.0015 The Total Price:t$330.00 You should make use of the NumberFormat class and DecimalFormat (in java.text package) to format the total price in the dollar format (NumberFormat) and the unit price using 4 digits after their decimal point (DecimalFormat using "0.0000"). SoupInCylinder class
  • 3. SoupInCylinder is a subclass of Soup class. It represents a soup 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 soup. height int The height of the cylinder of the soup. The following constructor method should be provided: publicSoupInCylinder(String id, double someUnitPrice, int someRadius, int someHeight) The radius is initialized to the value of the third parameter, the height is initialized to the value of the forth parameter, and the constructor of the parent class Soup should be called using the first and second parameters. Leave volume and totalPrice as their default values (defined in the parent’s constructor). The following method should be implemented: publicvoid computeTotalPrice() First, it computes the volume for the cylinder of the soup. (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 soup. (computed by volume * unitPrice) Also, the following method should be implemented: publicString toString() The toString() method inherited from Soup class should be used to create a new string, and display a cylinder soup's information using the following format: TheSoup in a Cylinder The Radius:tt5 The Height:tt10 The SoupId:tttomatosoup591 The Volume:tt785 The Unit Price:tt0.0022 The Total Price:t$1.73
  • 4. This toString method should make use of the toString method of the parent class. SoupInBox class SoupInBox is a subclass of Soup class. It represents a soup in a carton. It has the following attributes: Attribute name Attribute type Description height int The height of the box of the soup. width int The width of the box of the soup. depth int The depth of the box of the soup. The following constructor method should be provided: publicSoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int someDepth) 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 Soup should be called using the first and second parameters. Leave volume and totalPrice as their default value. The following method should be implemented: publicvoid computeTotalPrice() First, it computes the volume of the box of the soup. (computed by height*width*depth) Then compute the total price of the soup. (computed by volume * unitPrice) Also, the following method should be implemented: publicString toString() The toString() method inherited from the Soup class should be used to create a new string, and display a box soup's information using the following format: TheSoup in a Box The Height:tt5 The Width:tt10 The Depth:tt5 The SoupId:ttsplitPeaSoup515 The Volume:tt250
  • 5. The Unit Price:tt0.0055 The Total Price:t$1.38 This toString method should make use of the toString method of the parent class. SoupParser class The SoupParser class is a utility class that will be used to create a soup object (either a cylinder soup object or a box soup object) from a parsable string. The SoupParser class object will never be instantiated. It must have the following method: publicstatic Soup parseStringToSoup(String lineToParse) The parseStringToSoup method's argument will be a string in the following format: For a cylinder soup, shape/soupId/unitPrice/radius/height For a box soup, shape/soupId/unitPrice/height/width/depth A real example of this string would be: Cylinder/tomateSoup514/0.0054/5/10 OR Box/splitPeaSoup7192/0.0035/10/15/10 This method will parse this string, pull out the information, create a new SoupInCylinder or SoupInBox 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 SoupInCylinder and SoupInBox 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 Soup", "Add Compute Total Prices", "Search for Soup", and "List Soups". All input and output should be handled here. The main method should start by displaying this updated menu in this exact format: ChoicettAction ------tt------ AttAdd Soup CttCompute Total Prices DttSearch for Soup LttList Soups
  • 6. QttQuit ?ttDisplay Help Next, the following prompt should be displayed: What action would you like to perform? 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 Soup Your program should display the following prompt: Please enter a soup information to add: Read in the information and parse it using the soup parser. Then add the new soup object (created by soup parser) to the soup list. Compute Total Prices Your program should compute total price for all soups created so far by calling computeTotalPrice method for each of them in the soup list. After computing total prices, display the following: totalprices computed Search for Soup Your program should display the following prompt: Please enter a soupId to search: Read in the string and look up the soup list, if there exists a soup object with the same soup ID, then display the following: soupfound Otherwise, display this: soupnot found List Soups List all soups in the soup list. Make use of toString method defined in SoupInBox and SoupInCylinder classes. A real example is looked like this: The Soup in a Cylinder Container The Radius: 5 The Height: 10 The SoupId: chickensoup200 The Volume: 0 The Unit Price: 0.0054
  • 7. The Total Price: $0.00 The Soup in a Box Container The Height: 10 The Width: 15 The Depth: 10 The SoupId: tomatosoup03 The Volume: 0 The Unit Price: 0.0035 The Total Price: $0.00 If there is no soup in the soup list (the list is empty), then display following: nosoup 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 Attribute name Attribute type Description volume int The volume of the soup unitPrice double The price per unit of the soup totalPrice double The total price of the soup soupId String The Id of the soup SoupParser parseString ToSoup(lineToParse String): Soup Arizona State University, CSE205 Spring 2017, Assignment5 Assi nment +main(StringU): void +print
  • 8. Menu0:void Souplncylinder radius :int -height: int +Souplncylinder(String,double,int,int) ttoString0: String Sou #volume int 0 #unit Price:double #total Price: double 0.0 #soupld: String Soup (String,double) tgetSoupld0: String +toString(): String compute Total Price() void SouplnBox ght: int -width: int -depth: int tSoupInBox (String, nt ttoString0:String Solution PROGRAM CODE: Soup.java package soup; import java.text.DecimalFormat; import java.text.NumberFormat; public abstract class Soup { protected int volume; protected double unitPrice; protected double totalPrice; protected String soupId; Soup(String soupId, double unitPrice) { this.soupId = soupId; this.unitPrice = unitPrice; this.volume = 0; this.totalPrice = 0.0; } public String getSoupId() { return this.soupId; } @Override public String toString() { String unitPriceFormat = "#.####"; String totalPriceFormat = "$###.##";
  • 9. NumberFormat UPFormat = new DecimalFormat(unitPriceFormat); NumberFormat TPFormat = new DecimalFormat(totalPriceFormat); return " The SoupId:tt" + this.soupId+ " The Volume:tt" + this.volume + " The Unit Price:tt" + UPFormat.format(unitPrice) + " The Total Price:t" + TPFormat.format(this.totalPrice) + " "; } public abstract void computeTotalPrice(); } SoupInBox.java package soup; public class SoupInBox extends Soup{ private int height; private int width; private int depth; public SoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int someDepth) { super(id, someUnitPrice); this.height = someHeight; this.width = someWidth; this.depth = someDepth; } @Override public void computeTotalPrice() { volume = height * width * depth; totalPrice = volume * unitPrice; } @Override public String toString() { // TODO Auto-generated method stub return " The Soup in a Box The Height:tt" + height + " The Width:tt" + width +
  • 10. " The Depth:tt" + depth + super.toString(); } } SoupInCylinder.java package soup; public class SoupInCylinder extends Soup{ private int radius; private int height; public SoupInCylinder(String id, double someUnitPrice, int someRadius, int someHeight) { super(id, someUnitPrice); this.radius = someRadius; this.height = someHeight; } @Override public void computeTotalPrice() { volume = (int) (Math.PI*(radius*radius*height)); totalPrice = volume * unitPrice; } @Override public String toString() { // TODO Auto-generated method stub return " The Soup in a Cylinder "+ "The Radius:tt" + this.radius + " The Height:tt" + height + super.toString(); } } SoupParser.java package soup; public class SoupParser { public static Soup parseStringToSoup(String lineToParse) { String[] input = lineToParse.split("/"); if(input[0].toLowerCase().equals("cylinder"))
  • 11. { return new SoupInCylinder(input[1], Double.valueOf(input[2]), Integer.valueOf(input[3]), Integer.valueOf(input[4])); } else return new SoupInBox(input[1], Double.valueOf(input[2]), Integer.valueOf(input[3]), Integer.valueOf(input[4]), Integer.valueOf(input[5])); } } Assignment5.java package soup; // Assignment #: 5 //Arizona State University - CSE205 // Name: Your name // StudentID: Your id // Lecture: Your lecture time (for instance, MWF 10:40am) //Description: The Assignment 5 class displays a menu of choices // (add cylinder soup, box soup,search soup, // list soups, quit, display menu) to a user // and performs the chosen task. It will keep asking a user to // enter the next choice until the choice of 'Q' (Quit) is // entered. import java.io.*; //to use InputStreamReader and BufferedReader import java.util.*; //to use ArrayList public class Assignment5 { public static void main (String[] args) { char input1; String inputInfo = new String(); String line = new String(); boolean operation; // ArrayList object is used to store soup objects ArrayList soupList = new ArrayList(); try {
  • 12. printMenu(); // print out menu // create a BufferedReader object to read input from a keyboard InputStreamReader isr = new InputStreamReader (System.in); BufferedReader stdin = new BufferedReader (isr); do { System.out.println("What action would you like to perform?"); line = stdin.readLine().trim(); input1 = line.charAt(0); input1 = Character.toUpperCase(input1); if (line.length() == 1) { switch (input1) { case 'A': //Add Soup System.out.print("Please enter some soup information to add: "); inputInfo = stdin.readLine().trim(); Soup soup = SoupParser.parseStringToSoup(inputInfo); soupList.add(soup); break; case 'C': //Compute Total Prices for(Soup tempSoup: soupList) tempSoup.computeTotalPrice(); System.out.print("total prices computed "); break; case 'D': //Search for Soup System.out.print("Please enter a soupID to search: "); inputInfo = stdin.readLine().trim(); operation = false; for(Soup tempSoup: soupList) { if(tempSoup.getSoupId().equals(inputInfo)) { operation = true; break; }
  • 13. } if (operation == true) System.out.print("soup found "); else System.out.print("soup not found "); break; case 'L': //List Soups for(Soup tempSoup: soupList) System.out.println(tempSoup); break; case 'Q': //Quit break; case '?': //Display Menu printMenu(); break; default: System.out.print("Unknown action "); break; } } else { System.out.print("Unknown action "); } } while (input1 != 'Q'); // stop the loop when Q is read } catch (IOException exception) { System.out.println("IO Exception"); } } /** The method printMenu displays the menu to a use **/ public static void printMenu() { System.out.print("ChoicettAction " + "------tt------ " +
  • 14. "AttAdd Soup " + "CttCompute Total Prices " + "DttSearch for Soup " + "LttList Soups " + "QttQuit " + "?ttDisplay Help "); } } OUTPUT: Choice Action ------ ------ A Add Soup C Compute Total Prices D Search for Soup L List Soups Q Quit ? Display Help What action would you like to perform? A Please enter some soup information to add: Cylinder/tomateSoup514/0.0054/5/10 What action would you like to perform? A Please enter some soup information to add: Box/splitPeaSoup7192/0.0035/10/15/10 What action would you like to perform? C total prices computed What action would you like to perform? D Please enter a soupID to search: splitPeaSoup7192 soup found What action would you like to perform? L The Soup in a Cylinder
  • 15. The Radius: 5 The Height: 10 The SoupId: tomateSoup514 The Volume: 785 The Unit Price: 0.0054 The Total Price: $4.24 The Soup in a Box The Height: 10 The Width: 15 The Depth: 10 The SoupId: splitPeaSoup7192 The Volume: 1500 The Unit Price: 0.0035 The Total Price: $5.25 What action would you like to perform? Q