In: Computer Science
Write a Java Program to place a pizza ordering program. It creates a pizza ordered to the specifications that the user desires. It walks the user through ordering, giving the user choices, which the program then uses to decide how to make the pizza and how much the cost of the pizza will be. Note: Use dialog boxes for communicating with the user. Remember to use the JOptionPane class which is the graphical user interface (GUI) and Comments that are not read by the computer, they are for use by the programmer. They are to help a programmer document what the program does and how it accomplishes it. This is important when a programmer needs to modify code that is written by another person.
Task 1. Name the program, PizzaOrder.java
2. Write a welcome message that said, “Welcome to ___________________ Pizza.”
3. Ask the user to input his or her first name. “Enter your first name:”
4. A menu should display to the user: Pizza sizes (inches) Cost 10” $10.99 12” $12.99 14” $14.99 16” $16.99 What size pizza would you like? 10, 12, 14, or 16 (enter the number only):
5. After the user has inputted the number another print statement should ask “What type of crust do you want? (H)Hand-tossed, (T) Thin-crust, or (D) Deepdish (enter H, T, or D):”
6. After the user has inputted the type of crust another print statement asking All pizzas come with cheese. Additional toppings are $1.25 each, choose from: Pepperoni, Sausage, Onion, Mushroom Do you want Pepperoni? (Y/N):
7. After you inputted Yes, or No another question should pop up Do you want Sausage? (Y/N): then Do you want Onion? (Y/N): then Do you want Mushroom? (Y/N):
8. At the end, it should show a receipt depending on the input: Note: The sales tax is 8.875% (below is an example) Your order is as follows:
10-inch Pizza
Hand-tossed crust $ 10.99
Pepperoni $ 1.25
The subtotal cost of your order is: $ 12.24
The tax is: $ 1.09 ----------------
total is: $ 13.33
*Your order will be ready for pick up in 30 minutes*
Below is the java code for the above question:
SOLUTION
import java.util.*;
public class PizzaOrder {
public static void main(String[] args) {
double bp = 0;
System.out.println("Welcome to
___________________ Pizza.");
System.out.println("Enter your
first name:");
Scanner sc = new
Scanner(System.in);//taking input from the user
String name = sc.nextLine();
System.out.println(
"Pizza sizes (inches) Cost 10” $10.99 12” $12.99
14” $14.99 16” $16.99 What size pizza would you like? 10, 12, 14,
or 16 (enter the number only):");
int size = sc.nextInt();
System.out.println(
"What type of crust do you want? (H)Hand-tossed,
(T) Thin-crust, or (D) Deepdish (enter H, T, or D):");
String type = sc.nextLine();
System.out.println(
"All pizzas come with cheese. Additional
toppings are $1.25 each, choose from: Pepperoni, Sausage, Onion,
Mushroom Do you want Pepperoni? (Y/N):");
String pepp = sc.nextLine();
System.out.println("Do you want
Sausage? (Y/N):");
String saus = sc.nextLine();
System.out.println("Do you want
Onion? (Y/N):");
String onion = sc.nextLine();
System.out.println("Do you want
Mushroom? (Y/N):");
String mush = sc.nextLine();
System.out.println("Your order is as follows:");
// based on size calculating
if (size == 10) {
bp =
10.99;
System.out.println("10-inch Pizza");
System.out.println("Hand-tossed crust is $ " + bp);
if
(pepp.equalsIgnoreCase("Y")) {
System.out.println("Pepperoni $ 1.25");
bp = bp + 1.25;
} else if
(saus.equalsIgnoreCase("Y")) {
System.out.println("Sausage $ 1.25");
bp = bp + 1.25;
} else if
(onion.equalsIgnoreCase("Y")) {
System.out.println("Onion $ 1.25");
bp = bp + 1.25;
} else if
(mush.equalsIgnoreCase("Y")) {
System.out.println("Mushroom $ 1.25");
bp = bp + 1.25;
}
} else if (size == 12) {
bp =
12.99;
System.out.println("12-inch Pizza");
System.out.println("Hand-tossed crust is $ " + bp);
if
(pepp.equalsIgnoreCase("Y")) {
System.out.println("Pepperoni $ 1.25");
bp = bp + 1.25;
} else if
(saus.equalsIgnoreCase("Y")) {
System.out.println("Sausage $ 1.25");
bp = bp + 1.25;
} else if
(onion.equalsIgnoreCase("Y")) {
System.out.println("Onion $ 1.25");
bp = bp + 1.25;
} else if
(mush.equalsIgnoreCase("Y")) {
System.out.println("Mushroom $ 1.25");
bp = bp + 1.25;
}
} else if (size == 14) {
bp =
14.99;
System.out.println("14-inch Pizza");
System.out.println("Hand-tossed crust is $ " + bp);
if
(pepp.equalsIgnoreCase("Y")) {
System.out.println("Pepperoni $ 1.25");
bp = bp + 1.25;
} else if
(saus.equalsIgnoreCase("Y")) {
System.out.println("Sausage $ 1.25");
bp = bp + 1.25;
} else if
(onion.equalsIgnoreCase("Y")) {
System.out.println("Onion $ 1.25");
bp = bp + 1.25;
} else if
(mush.equalsIgnoreCase("Y")) {
System.out.println("Mushroom $ 1.25");
bp = bp + 1.25;
}
} else if (size == 16) {
bp =
16.99;
System.out.println("16-inch Pizza");
System.out.println("Hand-tossed crust is $ " + bp);
if
(pepp.equalsIgnoreCase("Y")) {
System.out.println("Pepperoni $ 1.25");
bp = bp + 1.25;
} else if
(saus.equalsIgnoreCase("Y")) {
System.out.println("Sausage $ 1.25");
bp = bp + 1.25;
} else if
(onion.equalsIgnoreCase("Y")) {
System.out.println("Onion $ 1.25");
bp = bp + 1.25;
} else if
(mush.equalsIgnoreCase("Y")) {
System.out.println("Mushroom $ 1.25");
bp = bp + 1.25;
}
}
System.out.println("The subtotal
cost of your order is: $" + String.format("%.2f", bp));//subtotal
cost
double tax = (bp * 8.875 /
100);
System.out.println("The tax is: $"
+ String.format("%.2f", tax));
double sum = bp + tax;
System.out.println("total is: $" +
String.format("%.2f", sum));//total cost
System.out.println("*Your order
will be ready for pick up in 30 minutes*");
}
}
OUTPUT
Welcome to ___________________ Pizza.
Enter your first name:
John
Pizza sizes (inches) Cost 10” $10.99 12” $12.99 14” $14.99 16”
$16.99 What size pizza would you like? 10, 12, 14, or 16 (enter the
number only):
14
What type of crust do you want? (H)Hand-tossed, (T) Thin-crust, or
(D) Deepdish (enter H, T, or D):
H
All pizzas come with cheese. Additional toppings are
$1.25 each, choose from: Pepperoni, Sausage, Onion, Mushroom Do you
want Pepperoni? (Y/N):
N
Do you want Sausage? (Y/N):
Y
Do you want Onion? (Y/N):
Y
Do you want Mushroom? (Y/N):
Y
Your order is as follows:
14-inch Pizza
Hand-tossed crust is $ 14.99
Sausage $ 1.25
The subtotal cost of your order is: $16.24
The tax is: $1.44
total is: $17.68
*Your order will be ready for pick up in 30 minutes*