In: Computer Science
Problem Statement
You have been hired by Mike and Diane's Pizza to write a program to take a customer's order. Based on the user's choices (i.e., pizza size, crust type, and toppings), a summary of the order and the total cost are displayed. Users named Mike or Diane receive a $2.00 discount. Here is an example program run (user input is in bold):
-Create the Scanner object, prompt the user and get firstName. You will need to import the Scanner class. Compile, debug, run, and test.
-Prompt user and get the pizza size. Write an if-else-if statement that sets the correct price based on the user's input (10, 12, 14, or 16). Run, and test the program for each possible input value.
-Prompt user and get crust choice. Don't forget to consume the remaining newline character left when reading a numeric value (pizza size). Write an if-else-if statement that compares the user's choice with the appropriate characters (make sure that both upper and lower case letters work). Assign crust to the appropriate string value. Run your program multiple times to make sure all possible values for crustType work correctly.
-Prompt user for topping choices one at a time. If a "y" or "Y" is entered add the topping to the toppings String and increment numberOfToppings.
-Use numberOfToppings to add the cost of additional toppings to the cost of the pizza.
-Compare the user's name to "Mike" and "Diane" (be sure that the comparison is not case sensitive). If the discount applies, print a message indicating that the user is eligible for a $2.00 discount and reduce cost by 2. Test your program using the owners' names (both capitalized and not) as well as a different name.
A sample input is below.
/********* PizzaCost.java *********/
import java.util.Scanner;
public class PizzaCost {
public static void main(String[] args) {
// Declaring variables
int pizzaSize;
int noOfOfToppings;
String name, cType="";
double pizzaAmt=0.0;
char crustType, pepperoni,
sausage,onion,mushroom;
double discountAmt =
0,taxAmount=0.0,tot=0.0;
String toppings="Cheese ";
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
// Getting the input entered by
the user
System.out.print("Enter the first
Name :");
name = sc.next();
if (name.equals("Mike") ||
name.equals("Diane")) {
discountAmt =
2;
}
//displaying the menu
System.out.println("Pizza Size
(inches)\tCost");
System.out.println("10\t\t$10.99");
System.out.println("12\t\t$12.99");
System.out.println("14\t\t$14.99");
System.out.println("16\t\t$16.99");
System.out.println("What size pizza
would you like?");
//getting the choice entered by the
user
System.out.print("10, 12, 14, or 16
(enter the number only): ");
pizzaSize = sc.nextInt();
if (pizzaSize == 10) {
pizzaAmt =
10.99;
} else if (pizzaSize == 12) {
pizzaAmt =
12.99;
} else if (pizzaSize == 14) {
pizzaAmt =
14.99;
} else if (pizzaSize == 16) {
pizzaAmt =
16.99;
}
//displaying the menu
System.out.print("(H)and-tossed,
(T)hin-crust, or (D)eep-dish (enter H, T, or D):");
//getting the choice entered by the
user
crustType =
sc.next().charAt(0);
switch (crustType) {
case 'H':
case 'h': {
cType = "Hand
tossed";
break;
}
case 'T':
case 't': {
cType = "Thin
crust";
break;
}
case 'D':
case 'd': {
cType = "Deep
dish";
break;
}
}
System.out.println("All pizzas come
with cheese.");
System.out.println("Additional
toppings are $1.25 each, choose from");
System.out.println("Pepperoni,
Sausage, Onion, Mushroom");
System.out.print("Do you want
Pepperoni? (Y/N): ");
pepperoni =
sc.next().charAt(0);
if(pepperoni=='y' ||
pepperoni=='Y')
{
pizzaAmt+=1.25;
toppings+="Pepperoni ";
}
System.out.print("Do you want
Sausage? (Y/N): ");
sausage =
sc.next().charAt(0);
if(sausage=='y' ||
sausage=='Y')
{
pizzaAmt+=1.25;
toppings+="Sausage ";
}
System.out.print("Do you want
Onion? (Y/N): ");
onion = sc.next().charAt(0);
if(onion=='y' || onion=='Y')
{
pizzaAmt+=1.25;
toppings+="Onion
";
}
System.out.print("Do you want
Mushroom? (Y/N): ");
mushroom =
sc.next().charAt(0);
if(mushroom=='y' ||
mushroom=='Y')
{
pizzaAmt+=1.25;
toppings+="Mushroom ";
}
//Displaying the output
System.out.println(name+", your
order is as follows:");
System.out.println(pizzaSize+" inch
pizza");
System.out.println(cType+"
crust");
System.out.println(toppings);
if(discountAmt==0)
{
System.out.println("You are eligible for the discount.");
}
else
{
System.out.println("You are eligible for a $2.00 discount");
}
pizzaAmt-=discountAmt;
taxAmount=pizzaAmt*0.08;
tot=pizzaAmt+taxAmount;
System.out.printf("The cost of your
order is: $%.2f\n",pizzaAmt);
System.out.printf("The tax is:
$%.2f\n",taxAmount);
System.out.printf("The total due
is: $%.2f\n",tot);
System.out.println("Your order will
be ready for pickup in 30 minutes.");
}
}
/****************************************************/
/****************************************************/
Output:
/****************************************************/