Project Description: 1)Develop a class that simulates a Pizza ordering system. I
ID: 3677205 • Letter: P
Question
Project Description:
1)Develop a class that simulates a Pizza ordering system. In this program, customer will be able to check prices, order pizza, review total price, and cancel order. The UML class diagram of PizzaOrdering class is shown below.
PizzaOrdering
LARGE_PIZZA_PRICE:double
MEDIUM_PIZZA_PRICE:double
SMALL_PIZZA_PRICE:double
totalExpense:double
PizzaOrdering ()
mainMenu():void
listPrices():void
placeOrder():void
displayTotal():void
cancelOrder():void
2)User will enter the main menu first and choose from five options:
1.List prices;
2.Place order;
3.Display total amount to pay;
4.Cancel the current order;
5.Exit program.
User will be asked “Please in put the choice (1-5):” and input a number and hit enter to choose the option.
3)List price option will display the prices of three difference pizza size and return to main menu immediately:
Large pizza: $16.99
Medium pizza: $14.99
Small pizza: $12.99
4)The prices should be pre-stored in three constants LARGE_PIZZA_PRICE, MEDIUM_PIZZA_PRICE and SMALL_PIZZA_PRICE rather than hard coded in the println statements.
5)Place order option will
1.Ask user to input the size of pizza to order first and take user input of integer between 1 and 3:
Please choose the size of pizza (1. Large; 2. Medium; 3. Small):
2.Then ask user to input the amount of the pizzas to order and allow the maximum of 10 pizza to be ordered in one round:
Please input the amount of pizza you want to order (1-10):
3.The subtotal is then calculated as unit price times amount and is added to the total expense. It is not necessary to store anything. Just update the total expense variable value;
4.Finally, ask user if they want to continue ordering more and check the user input for y or n:
Do you want to order more? (y/n)
5.If “y” (or “Y”) is found, go back to step 1. Otherwise, exit to mainMenu.
6)Display total option will display the total expense of the order and immediate exit to main menu:
Your current total is $32.97.
7)Cancel order option will reset the total expense to 0 and display the message and then exit to main menu:
Your order is canceled and your total expense is 0 now.
8)The exit option will exit the program.
PizzaOrdering class:
1)Variables and constants
a.LARGE_PIZZA_PRICE, MEDIUM_PIZZA_PRICE and SMALL_PIZZA_PRICE stores the unit prices of three sizes of pizza
b.totalExpense stores the total amount of money due for current order
c.A totalExpense variable is defined to store the current total
d.All variables are initialized to its initial values
2)Constructor and Methods
Default Constructor is required. You can initialize any non-constant fields like totalExpense here if you have not done so when declaring it;
Method mainMenu is the entry point of this class, which displays the main menu and use a loop to interact with user. Once user choice is read in. The corresponding methods will be called. You may consider a switch statement to delegate the task according to the user input. If user choose to exit, the loop will end and the program will quit;
Method listPrices will display the unit prices of three different sizes of pizza and immediately return to main menu;
Method placeOrder handle the pizza ordering and update the total expense variable;
Method displayTotal will display the current total expense;
Method cancelOrder will display a message and reset the total expense.
PizzaOrderingRunner class
1)This program have the main method as the entry point. In the main method, it will create a PizzaOrdering object and call its mainMenu method to start the program.
2)Must have this class. Do not combine the runner responsibility to the mail PizzaOrdering class!
Sample Output: user inputs are highlighted in red
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 0
Please in put the choice (1-5): -1
Please in put the choice (1-5): 16
Please in put the choice (1-5): 1
Large pizza: $16.99
Medium pizza: $14.99
Small pizza: $12.99
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $0.00
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 2
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 0
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 45
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 3
Please input the amount of pizza you want to order (1-10): -1
Please input the amount of pizza you want to order (1-10): 19
Please input the amount of pizza you want to order (1-10): 6
Do you want to order more? (y/n) y
Please choose the size of pizza (1. Large; 2. Medium; 3. Small): 1
Please input the amount of pizza you want to order (1-10): 1
Do you want to order more? (y/n) n
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $94.93
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 4
Your order is canceled and your total expense is 0 now.
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 3
Your current total is $0.00
Welcome to the pizza ordering system:
1. List prices;
2. Place order;
3. Display total amount to pay;
4. Cancel the current order;
5. Exit program.
Please in put the choice (1-5): 5
Thank you for using!
PizzaOrdering
LARGE_PIZZA_PRICE:double
MEDIUM_PIZZA_PRICE:double
SMALL_PIZZA_PRICE:double
totalExpense:double
PizzaOrdering ()
mainMenu():void
listPrices():void
placeOrder():void
displayTotal():void
cancelOrder():void
Explanation / Answer
import java.util.Scanner;
class PizzaOrdering
{
public static void main(String args[])
{
//initializing variables
public static final double LARGE_PIZZA_PRICE= 16.99;
public static final doube MEDIUM_PIZZA_PRICE=14.99;
public static final double SMALL_PIZZA_PRICE=12.99;
double total=0;
int o=0,q=0;//option,amount
string o1;
public void listprices() //for listing prices
{
System.out.println("Large pizza: $ " + LARGE_PIZZA_PRICE );
System.out.println("MEDIUM pizza: $ " + MEDIUM _PIZZA_PRICE );
System.out.println("small pizza: $ " + SMALL_PIZZA_PRICE );
}
public void placeordering()//take orders
{
While(true)//runs until option 1,2,3 and q <=10
{
If(o==1||0==2||0==3)
{
System.out.println("Please Enter the number between 1 to 3" )
Scanner in = new Scanner(System.in);
System.out.println("Please choose the size of pizza (1. Large; 2. Medium; 3. Small)" );
o=in.nextInt();//option
}
if(q<=10 &&q >0)
{
System.out.println("Please input the amount of pizza you want to order (1-10): " );
q=in.nextInt();
}
total1();
System.out.println("Do you want to order more? (y/n)" );
o1=in.nextline();
if(o1="y")
return false;
}//while closing
}//method
public void total1()
{
switch (o) {
case 1:
total += LARGE_PIZZA_PRICE *q;
break;
case 2:
total += MEDIUM_PIZZA_PRICE *q;
break;
case 3:
total+= SMALL_PIZZA_PRICE *q;
break;
default:
total+= 0;
break;
}
}
Public void displayTotal()
{
System.out.println("Your current total is $"+total);
}
public void cancelOrder()
{
total=0;//reseting total value
System.out.println("Your current total is $"+total);
}
PizzaOrdering p=new PizzaOrdering();
//creating object for calling methods
while(true)
{
System.out.println("Welcome to the pizza ordering system: ");
System.out.println("1. List prices;");
System.out.println("2. Place order;");
System.out.println("3. Display total amount to pay;");
System.out.println("4. Cancel the current order;");
System.out.println("5. Exit program.");
System.out.println("Please in put the choice (1-5): ");
int c=in.nextInt();
switch (c) {
case 1: p. listprices();
break;
case 2: p. placeordering();
break;
case 3: p.displayTotal();
break;
case 4:p. cancelOrder();
break;
case 5: java.lang.System.exit();
break;
default: java.lang.System.exit();
break;
}
}//while
System.out.println("Thank you for using!");
}//main
}//class
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.