These are the outputs which should match they are 4 of them
These are the outputs which should match they are 4 of them :-
output 1 -
output 2 -
output 3 -
output 4 -
Here is the Assingment5.java file can make changes to it :-
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.
public Soup(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 :
public String 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:
public abstract void computeTotalPrice();
The following public method should be provided:
public String toString()
toString method returns a string of the following format:
\ The SoupId:\\t\\ttomatosoup591\ 
 The Volume:\\t\\t150\ 
 The Unit Price:\\t\\t0.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:
public SoupInCylinder(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:
public void 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:
public String 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:
\ The Soup in a Cylinder\ 
 The Radius:\\t\\t5\ 
 The Height:\\t\\t10\ 
 The SoupId:\\t\\ttomatosoup591\ 
 The Volume:\\t\\t785\ 
 The Unit Price:\\t\\t0.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:
public SoupInBox(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:
public void 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:
public String 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:
\ The Soup in a Box\ 
 The Height:\\t\\t5\ 
 The Width:\\t\\t10\ 
 The Depth:\\t\\t5\ 
 The SoupId:\\t\\tsplitPeaSoup515\ 
 The Volume:\\t\\t250\ 
 The Unit Price:\\t\\t0.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:
public static 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:
Choice\\t\\tAction\ 
 ------\\t\\t------\ 
 A\\t\\tAdd Soup\ 
 C\\t\\tCompute Total Prices\ 
 D\\t\\tSearch for Soup\ 
 L\\t\\tList Soups\ 
 Q\\t\\tQuit\ 
 ?\\t\\tDisplay 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:
total prices 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:
soup found\
Otherwise, display this:
soup not 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:
no soup\
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 | 
Solution
Assignment.java:
package testProject;
// 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.text.NumberFormat;
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 someSoup=SoupParser.parseStringToSoup(inputInfo);
soupList.add(someSoup);
/***********************************************************************************
*** ADD your code here to create an object of one of child classes of Soup class
*** and add it to the soupList
***********************************************************************************/
break;
case \'C\': //Compute Total Prices
for (Object object : soupList) {
Soup tempsoup=(Soup) object;
tempsoup.computeTotalPrice();
}
/***********************************************************************************
*** ADD your code here to compute the total price for each soup in the soupList.
***********************************************************************************/
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 (Object object : soupList) {
Soup tempsoup=(Soup) object;
if(tempsoup.getSoupId().equals(inputInfo)){
operation=true;
break;
}
}
/***********************************************************************************
*** ADD your code here to search the soup with the entered soupId and set operation
*** to true or false based on its result
***********************************************************************************/
if (operation == true)
System.out.print(\"soup found\ \");
else
System.out.print(\"soup not found\ \");
break;
case \'L\': //List Soups
if(soupList.size()==0)
System.out.println(\"no soup\ \");
else{
for (Object object : soupList) {
Soup tempsoup=(Soup) object;
System.out.println(tempsoup.toString());
}
}
/***********************************************************************************
*** ADD your code here to print out all soup objects. If there is no soup,
*** print \"no soup\ \"
***********************************************************************************/
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(\"Choice\\t\\tAction\ \" +
\"------\\t\\t------\ \" +
\"A\\t\\tAdd Soup\ \" +
\"C\\t\\tCompute Total Prices\ \" +
\"D\\t\\tSearch for Soup\ \" +
\"L\\t\\tList Soups\ \" +
\"Q\\t\\tQuit\ \" +
\"?\\t\\tDisplay Help\ \ \");
}
}
Soup.java:
package testProject;
import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Locale;
public abstract class Soup {
   int volume=0;
    double unitPrice;
    double totalPrice=0.0;
    String soupId;
    public Soup(String soupId,double unitPrice) {
        this.unitPrice = unitPrice;
        this.soupId = soupId;
    }
    public String getSoupId() {
        return soupId;
    }
    @Override
    public String toString() {
        NumberFormat usFormat = NumberFormat.getCurrencyInstance(new Locale(\"en\",\"US\"));
        DecimalFormat decFormat = new DecimalFormat(\"#.####\");
       
        return \"\ The SoupId:\\t\\t\"+soupId+\"\ The Volume:\\t\\t\"+volume+\"\ The Unit Price:\\t\\t\"+decFormat.format(unitPrice)+\"\ The Total Price:\\t\"+usFormat.format(totalPrice)+\"\ \ \";
    }
    public abstract void computeTotalPrice();
   
   
 }
SoupInBox.java:
package testProject;
import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Locale;
public class SoupInBox extends Soup{
   int height,width,depth;
   
    public SoupInBox(String id, double someUnitPrice, int someHeight, int someWidth, int someDepth){
        super(id, someUnitPrice);
        this.width=someWidth;
        this.height=someHeight;
        this.depth=someDepth;
    }
   @Override
    public void computeTotalPrice() {
        // TODO Auto-generated method stub
        volume=(int) (Math.PI*(height*depth*width));
        totalPrice=volume * unitPrice;
       
       
    }
   public String toString(){
        NumberFormat usFormat = NumberFormat.getCurrencyInstance(new Locale(\"en\",\"US\"));
        DecimalFormat decFormat = new DecimalFormat(\"#.####\");
       
        return \"\ The Soup in a Box\ The Height:\\t\\t\"+height+\"\ The Width:\\t\\t\"+width+\"\ The Depth:\\t\\t\"+depth+\"\ The SoupId:\\t\\t\"+soupId+\"\ The Volume:\\t\\t\"+volume+\"\ The Unit Price:\\t\\t\"+decFormat.format(unitPrice)+\"\ The Total Price:\\t\"+usFormat.format(totalPrice)+\"\ \ \";
               
    }
 }
SoupInCylinder.java:
package testProject;
import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Locale;
public class SoupInCylinder extends Soup{
   int radius;
    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() {
        // TODO Auto-generated method stub
        volume=(int) (Math.PI*(radius*radius*height));
        totalPrice=volume * unitPrice;
       
       
    }
   public String toString(){
        NumberFormat usFormat = NumberFormat.getCurrencyInstance(new Locale(\"en\",\"US\"));
        DecimalFormat decFormat = new DecimalFormat(\"#.####\");
       
        return \"\ The Soup in a Cylinder\ The Radius:\\t\\t\"+radius+\"\ The Height:\\t\\t\"+height+\"\ The SoupId:\\t\\t\"+soupId+\"\ The Volume:\\t\\t\"+volume+\"\ The Unit Price:\\t\\t\"+decFormat.format(unitPrice)+\"\ The Total Price:\\t\"+usFormat.format(totalPrice)+\"\ \ \";
    }
}
SoupParser.java:
package testProject;
public class SoupParser {
public static Soup parseStringToSoup(String lineToParse){
//shape/soupId/unitPrice/radius/height;
String temp[]=lineToParse.split(\"/\");
String shape=temp[0].toLowerCase();
Soup s=null;
if(shape.equals(\"cylinder\"))
s=new SoupInCylinder(temp[1],Double.parseDouble(temp[2]), Integer.parseInt(temp[3]), Integer.parseInt(temp[4]));
else if(shape.equals(\"box\"))
s=new SoupInBox(temp[1],Double.parseDouble(temp[2]), Integer.parseInt(temp[3]), Integer.parseInt(temp[4]),Integer.parseInt(temp[5]));
return s;
}
}
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?
L
The Soup in a Cylinder
The Radius: 5
The Height: 10
The SoupId: tomateSoup514
The Volume: 0
The Unit Price: 0.0054
The Total Price: $0.00
The Soup in a Box
The Height: 10
The Width: 15
The Depth: 10
The SoupId: splitPeaSoup7192
The Volume: 0
The Unit Price: 0.0035
The Total Price: $0.00
What action would you like to perform?
D
Please enter a soupID to search:
tomatoSoup514
soup not found
What action would you like to perform?
D
Please enter a soupID to search:
tomateSoup514
soup found
What action would you like to perform?
?
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?
C
total prices computed
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: 4712
The Unit Price: 0.0035
The Total Price: $16.49
What action would you like to perform?
B
Unknown action
What action would you like to perform?
?
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?
Q















