import java.util.Scanner; public class Juice_ordering  { public static void main(String [] args) { Food[] foodArray = new Food[4]; foodArray[0] = new Juice("Apple","C01",5.00, "Which is very popular juice in our shop.","Apple",1); foodArray[1] = new Juice("Orange","I02",8.00, "Which is very popular juice in our shop.","Orange",2); foodArray[2] = new Snack("Cheez-It","SC001",15.00, "Which is very popular juice in shop.","tin","small"); foodArray[3] = new Snack("Cheez-It","SC002",18.00, "Nice snack.","tin","medium");     boolean loopagain = true; while(loopagain){ System.out.println("1.\t Display Food"); System.out.println("2.\t Order Food"); System.out.println("3.\t Add Food"); System.out.println("4.\t Delete Food"); System.out.println("0.\t To Exit"); double total=0; Scanner in = new Scanner(System.in); System.out.println("Please enter your choice:"); int choice=in.nextInt(); switch (choice) { case 1: System.out.println("1.\t Display Fruit Juice Order"); System.out.println("2.\t Display Snack Order"); System.out.println("Please enter your choice:"); Scanner on = new Scanner(System.in); int food_choice=on.nextInt(); switch(food_choice){ case 1:displayJuice(foodArray); break; case 2:displaySnack(foodArray); } break; case 2:Scanner ordercode = new Scanner(System.in); System.out.println("Enter the Food Code that wanted to order:"); String code = ordercode.nextLine(); double price=orderprocess(foodArray,code); if (price == -1) System.out.println("Invalid Order Code"); else System.out.println("Price =Rm " +price +"\n"); total+=price; break; case 3:Scanner addcode = new Scanner(System.in); System.out.println("Enter the Food Code that wanted to add order:"); String add = addcode.nextLine(); double addprice=addorderprocess(foodArray,add); if (addprice == -1) System.out.println("Invalid Order Code"); else System.out.println("Price =Rm " +addprice +"\n"); total+=addprice; break; case 4: Scanner dltcode = new Scanner(System.in); System.out.println("Enter the Food Code that wanted to delete order:"); String dlt = dltcode.nextLine(); double dltprice=dltorderprocess(foodArray,dlt); if (dltprice == -1) System.out.println("Invalid Order Code"); else System.out.println("You have delete an item"); total-=dltprice; break; case 0: System.out.println("Bye"); loopagain=false; break; default: System.out.println("Invalid choice"); } } } public static void displayJuice(Food[] foodArray){ for (int i = 0; i < foodArray.length; ++i) { if (foodArray[i] instanceof Juice){ System.out.println("\nJuice\n============"); System.out.println(foodArray[i]); } } } public static void displaySnack(Food[] foodArray){ for (int i = 0; i < foodArray.length; ++i) { if (foodArray[i] instanceof Snack){ System.out.println("\nSnack\n============"); System.out.println(foodArray[i]); } } } public static double orderprocess(Food[] foodArray,String code){ for (int i = 0; i < foodArray.length; ++i) { if(foodArray[i].getcode().compareTo(code)==0){ return foodArray[i].getprice(); } }return -1; } public static double addorderprocess(Food[] foodArray,String add){ for (int a = 0; a < foodArray.length; ++a) { if(foodArray[a].getcode().compareTo(add)==0){ return foodArray[a].getprice(); } }return -1; } public static double dltorderprocess(Food[] foodArray,String dlt){ for (int b = 0; b < foodArray.length; ++b) { if(foodArray[b].getcode().compareTo(dlt)==0){ return foodArray[b].getprice(); } }return -1; } }   class Snack extends Food{ private String packing; private String size; public Snack(){ } public Snack(String name, String code, double price,String description ,String packing,String size ){ super(name, code,price,description); this.packing= packing; this.size= size; } public String toString(){ return super.toString() + "\nPacking: " + packing + "\nSize: " + size; } }    class Juice extends Food{ private String flavor; private int cup ; public Juice(){ } public Juice(String name, String code, double price,String description, String flavor,int cup){ super(name,code,price,description); this.flavor = flavor; this.cup = cup; } public String toString(){ return super.toString() + "\nFlavor: " + flavor+ "\nCup: " + cup; } }  abstract class Food{ private String name; private String code; private double price; private String description; public Food(){ } public Food(String name ,String code,double price,String description){ this.name = name ; this.code = code ; this.price = price ; this.description =description ; } public void setname(String name){ this.name = name; } public void setcode(String code){ this.code = code; } public void setprice(Double price){ this.price = price; } public void setdescription(String description){ this.description = description; } public String getname(){ return name; } public String getcode(){ return code; } public Double getprice(){ return price; } public String getdescription(){ return description; } public String toString(){ return "Name: " + name + "\nCode: " + code + "\nPrice: " + price + "\nDescription: " + description; } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Someone help me , based on the java code given , how to draw the UML class diagram.

import java.util.Scanner;
public class Juice_ordering 
{

public static void main(String [] args)
{

Food[] foodArray = new Food[4];

foodArray[0] = new Juice("Apple","C01",5.00, "Which is very popular juice in our shop.","Apple",1);
foodArray[1] = new Juice("Orange","I02",8.00, "Which is very popular juice in our shop.","Orange",2);


foodArray[2] = new Snack("Cheez-It","SC001",15.00, "Which is very popular juice in shop.","tin","small");
foodArray[3] = new Snack("Cheez-It","SC002",18.00, "Nice snack.","tin","medium");

 

 

boolean loopagain = true;

while(loopagain){

System.out.println("1.\t Display Food");
System.out.println("2.\t Order Food");
System.out.println("3.\t Add Food");
System.out.println("4.\t Delete Food");
System.out.println("0.\t To Exit");

double total=0;

Scanner in = new Scanner(System.in);
System.out.println("Please enter your choice:");

int choice=in.nextInt();

switch (choice) {
case 1:
System.out.println("1.\t Display Fruit Juice Order");
System.out.println("2.\t Display Snack Order");
System.out.println("Please enter your choice:");

Scanner on = new Scanner(System.in);
int food_choice=on.nextInt();

switch(food_choice){
case 1:displayJuice(foodArray);
break;
case 2:displaySnack(foodArray);
}
break;

case 2:Scanner ordercode = new Scanner(System.in);
System.out.println("Enter the Food Code that wanted to order:");
String code = ordercode.nextLine();


double price=orderprocess(foodArray,code);
if (price == -1)
System.out.println("Invalid Order Code");
else
System.out.println("Price =Rm " +price +"\n");
total+=price;

break;
case 3:Scanner addcode = new Scanner(System.in);
System.out.println("Enter the Food Code that wanted to add order:");
String add = addcode.nextLine();

double addprice=addorderprocess(foodArray,add);
if (addprice == -1)
System.out.println("Invalid Order Code");
else
System.out.println("Price =Rm " +addprice +"\n");
total+=addprice;

break;
case 4: Scanner dltcode = new Scanner(System.in);
System.out.println("Enter the Food Code that wanted to delete order:");
String dlt = dltcode.nextLine();

double dltprice=dltorderprocess(foodArray,dlt);
if (dltprice == -1)
System.out.println("Invalid Order Code");
else
System.out.println("You have delete an item");
total-=dltprice;
break;

case 0: System.out.println("Bye");
loopagain=false;
break;
default: System.out.println("Invalid choice");
}
}

}

public static void displayJuice(Food[] foodArray){
for (int i = 0; i < foodArray.length; ++i) {

if (foodArray[i] instanceof Juice){

System.out.println("\nJuice\n============");
System.out.println(foodArray[i]);
}
}
}

public static void displaySnack(Food[] foodArray){

for (int i = 0; i < foodArray.length; ++i) {

if (foodArray[i] instanceof Snack){

System.out.println("\nSnack\n============");
System.out.println(foodArray[i]);
}
}
}

public static double orderprocess(Food[] foodArray,String code){
for (int i = 0; i < foodArray.length; ++i) {
if(foodArray[i].getcode().compareTo(code)==0){
return foodArray[i].getprice();
}
}return -1;
}

public static double addorderprocess(Food[] foodArray,String add){
for (int a = 0; a < foodArray.length; ++a) {
if(foodArray[a].getcode().compareTo(add)==0){
return foodArray[a].getprice();
}
}return -1;
}

public static double dltorderprocess(Food[] foodArray,String dlt){
for (int b = 0; b < foodArray.length; ++b) {
if(foodArray[b].getcode().compareTo(dlt)==0){
return foodArray[b].getprice();
}
}return -1;
}
}

 

class Snack extends Food{
private String packing;
private String size;

public Snack(){
}

public Snack(String name, String code, double price,String description ,String packing,String size ){
super(name, code,price,description);
this.packing= packing;
this.size= size;
}

public String toString(){
return super.toString() + "\nPacking: " + packing + "\nSize: " + size;
}
}

 

 class Juice extends Food{
private String flavor;
private int cup ;

public Juice(){
}

public Juice(String name, String code, double price,String description, String flavor,int cup){
super(name,code,price,description);
this.flavor = flavor;
this.cup = cup;
}


public String toString(){
return super.toString() + "\nFlavor: " + flavor+ "\nCup: " + cup;
}
}

 abstract class Food{
private String name;
private String code;
private double price;
private String description;

public Food(){
}

public Food(String name ,String code,double price,String description){

this.name = name ;
this.code = code ;
this.price = price ;
this.description =description ;
}


public void setname(String name){
this.name = name;
}

public void setcode(String code){
this.code = code;
}

public void setprice(Double price){
this.price = price;
}

public void setdescription(String description){
this.description = description;
}

public String getname(){
return name;
}

public String getcode(){
return code;
}

public Double getprice(){
return price;
}

public String getdescription(){
return description;
}

public String toString(){
return "Name: " + name + "\nCode: " + code + "\nPrice: " + price + "\nDescription: " + description;
}


}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 8 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY