Question

In: Computer Science

Write a JAVA program to store some details of pizzas (menu item number, size, base, extra...

Write a JAVA program to store some details of pizzas (menu item number, size, base, extra cheese, extra
garlic), curries (menu item number, size, curry type) and softdrinks (menu item number, size,
flavour, bottle or can) in a single array, with the options of listing all menu items or deleting a
particular menu item.
Your program must continuously prompt the user to choose an option from a list and act on that
option, until the exit option is chosen. (See the sample output below.) If a menu item is not found,
output "Not found" instead of "Done".


You must use inheritance and polymorphism to model your Pizza, Curry and SoftDrink classes (use
those exact class names) as subclasses of the same base class, which forms the basis for the array.

Note: Be very careful to reproduce the output exactly. Copy-and-paste is highly recommended to
avoid minor typographical errors that drive you crazy when submitting online!


Sample Input/Output:
Welcome to Great International Food Court
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist,
(Q)uit
p
Enter the menu item number
123
Enter the size
12"
Enter the base
Hand-tossed
Enter extra cheese
Yes
Enter extra garlic
Yes
Done
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit
c
Enter the menu item number
456
Enter the size
Large
Enter the curry type
Vindaloo
Done
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit
s
Enter the menu item number
789
Enter the size
Large
Enter the flavour
Coke
Enter whether it is a bottle or can
Bottle
Done
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit
d
Enter the menu item number
456
Done
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit
l
Pizza: 123, 12", Hand-tossed, Yes, Yes
Soft Drink: 789, Large, Coke, Bottle
Done
MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit
q

Solutions

Expert Solution

Please find your solution below and if any doubt comment and do upvote.

public class Pizza{
//class variables
int menuItemNumber;
String base,size;
boolean extraCheese,extraGarlic;
//constructor
public Pizza(int menuItemNumber, String size, String base, boolean extraCheese, boolean extraGarlic) {
this.menuItemNumber = menuItemNumber;
this.size = size;
this.base = base;
this.extraCheese = extraCheese;
this.extraGarlic = extraGarlic;
}
//tostring method
public String toString(){
return this.menuItemNumber + " "+ this.size+" "+this.base+" "+this.extraCheese+" "+this.extraGarlic;
}
}

--------------------------------------------------------------------------------------------------------------------------------------------

public class Curry {
//class variables
int menuItemNumber;
String curryType,size;
//constructor
public Curry(int menuItemNumber, String size, String curryType) {
this.menuItemNumber = menuItemNumber;
this.size = size;
this.curryType = curryType;
}
//to string method
public String toString(){
return this.menuItemNumber + " "+ this.size+" "+this.curryType;
}
}

-----------------------------------------------------------------------------------------------------------------

public class softDrink {
//class variables
int menuItemNumber;
String flavour,type,size;
//constructor
public softDrink(int menuItemNumber, String size, String flavour, String type) {
this.menuItemNumber = menuItemNumber;
this.size = size;
this.flavour = flavour;
this.type = type;
}
//toString method
public String toString(){
return this.menuItemNumber + " "+ this.size+" "+this.flavour+" "+this.type;
}
}

------------------------------------------------------------------------------------------------------------

import java.util.ArrayList;
import java.util.Scanner;

/**
*
* @author prmsh
*/
public class TestMenu extends Pizza{
public static void main(String args[]){
ArrayList yourOrder = new ArrayList(); //i stores order data
System.out.println("Welcome to Great International Food Court");
Scanner sc = new Scanner(System.in);
while(true){
//menu displaying
System.out.println("MENU: add (P)izza, add (C)urry, add (S)oft drink, (D)elete, (L)ist, (Q)uit");
String choice = sc.nextLine();
if(choice.equals("p") ||choice.equals("P")){ //this is for pizza
System.out.println("Enter menu item number");
int menuItem = sc.nextInt();
System.out.println("Enter size");
String size = sc.nextLine();
sc.nextLine();
System.out.println("Enter the base");
String base = sc.nextLine();
sc.nextLine();
System.out.println("Enter extra cheese");
boolean Cheese = sc.nextBoolean();
sc.nextLine();
System.out.println("Enter extra Garlic");
boolean Garlic = sc.nextBoolean();
Pizza pizza = new Pizza(menuItem,size,base,Cheese,Garlic);
yourOrder.add(pizza);
System.out.println("Done");
}
else if(choice.equals("c") ||choice.equals("C")){ //this is for curry
System.out.println("Enter menu item number");
int menuItem = sc.nextInt();
System.out.println("Enter size");
String size = sc.nextLine();
sc.nextLine();
System.out.println("Enter curry type");
String curryType = sc.nextLine();
sc.nextLine();
Curry curry = new Curry(menuItem,size,curryType);
yourOrder.add(curry);
System.out.println("Done");
}
else if(choice.equals("s") ||choice.equals("S")){//this is for soft drinks
System.out.println("Enter menu item number");
int menuItem = sc.nextInt();
System.out.println("Enter size");
String size = sc.nextLine();
sc.nextLine();
System.out.println("Enter flavour");
String flavour = sc.nextLine();
System.out.println("Enter whether it is a bottle or can");
String type = sc.nextLine();
sc.nextLine();
softDrink drink = new softDrink(menuItem,size,flavour,type);
yourOrder.add(drink);
System.out.println("Done");
}
else if(choice.equals("d") ||choice.equals("D")){ //to delte order
System.out.println("Enter posiyion to delete");
int number = sc.nextInt();
yourOrder.remove(number);
}
else if(choice.equals("l") ||choice.equals("L")){//to show all data
for(int i=0;i<yourOrder.size();i++){
System.out.println(yourOrder.get(i));
}
}
else if(choice.equals("q") ||choice.equals("Q")){ //safely exiting
System.out.println("Thank you!!1");
break;
}
}
}

public TestMenu(int menuItemNumber, String size, String base, boolean extraCheese, boolean extraGarlic) {
super(menuItemNumber, size, base, extraCheese, extraGarlic);
}
}

output:


Related Solutions

JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that...
JAVA FILE PROGRAM Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program...
in java Write a Java Program that displays a menu with five different options: 1. Lab...
in java Write a Java Program that displays a menu with five different options: 1. Lab Test Average Calculator 2. Dice Roll 3. Circle Area Calculator 4. Compute Distance 5. Quit The program will display a menu with each of the options above, and then ask the user to enter their choice. There is also a fifth option to quit, in which case, the program will simply display a goodbye message. Based on the user’s choice, one of the options...
in java Write a contacts database program that presents the user with a menu that allows...
in java Write a contacts database program that presents the user with a menu that allows the user to select between the following options: Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java...
PROGRAM MUST BE WRITTEN IN JAVAFX Develop a program flowchart and then write a menu-driven Java program that will solve the following problem. The program uses one and two-dimensional arrays to accomplish the tasks specified below. The menu is shown below. Please build a control panel as follows: (Note: the first letter is shown as bold for emphasis and you do not have to make them bold in your program.) Help SetParams FillArray DisplayResults Quit Upon program execution, the screen...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside file there should be items: Open, Save, and Save As. Selecting open prompts the user to input a file name to a txt document containing employee information and displays a Jtable with the information, which can be edited. With column headers {"First Name" , "Last Name" , "Occupation" , "Office #"} Example: Gary Osbourn Teacher 113 Michelle Ramirez Teacher 101 Ava Gomez Principal 120...
Write a java program that will first display the following menu: Choose one of the following...
Write a java program that will first display the following menu: Choose one of the following 1- To add 2 double integers 2- To add 2 integer numbers 3- To add 3 double numbers 4- To add 3 integer numbers After reading user’s choice, use a switch case statement to call the corresponding method Void add 1 (double n1, double n2) Void add2() Double add3 (double n1, double n2, double n3) Double add4 ()
Java Math Tutor: Write a program that displays a menu as shown in the sample run....
Java Math Tutor: Write a program that displays a menu as shown in the sample run. You can enter 1, 2, 3, or 4 for choosing an addition, subtraction, multiplication, or division test. After a test is finished, the menu is redisplayed. You may choose another test or enter 5 to exit the system. Each test generates two random single-digit numbers to form a question for addition, subtraction, multiplication, or division. For a subtraction such as number1 – number2, number1...
Java Write a menu driven program that implements the following linked list operations : INSERT (at...
Java Write a menu driven program that implements the following linked list operations : INSERT (at the beginning) INSERT_ALPHA (in alphabetical order) DELETE (Identify by contents, i.e. "John", not #3) COUNT CLEAR
java code Write a program that gives the user a menu of six choices (use integers)...
java code Write a program that gives the user a menu of six choices (use integers) to select from. The choices are circle, triangle, cone, cylinder, sphere, and quit. (The formulas are given below.) Once the figure is calculated, an informative message should be printed and the user shown the menu again, so that another choice can be made. The formulas are: Area of circle: a = 3.14 * radius * radius Area of triangle: a = ½ base *...
Write a menu driven Java program which uses a method for each of the following operations:...
Write a menu driven Java program which uses a method for each of the following operations: (Note : The user should be allowed to repeat the operations as long as he wants to. Use appropriate number of parameters and return type for each method.) A. to find the sum of the following series (up to N terms). The program should    display the terms:              22 + 42 + 62… For example, if N=4, then the program should display the following...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT