Tuesday, October 27, 2020

#433 Write a JAVA program to store some

Write a JAVA program to store some - Computer Science

ChemistryExplain daily providing Q&A content “#433 Write a JAVA program to store some" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs

ChemistryExplain “#433 Write a JAVA program to store some in Computer science, Ba computer science, Berkeley computer science

Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.

 ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.

For More Chegg Questions

Free Chegg Question

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

Free Chegg AnswerFor More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain  

Free Chegg Answer

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);
}
}

ChemistryExplain “#433 Write a JAVA program to store some in Computer science, Ba computer science, Berkeley computer science

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home