Question

In: Computer Science

Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...

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*

Solutions

Expert Solution

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*


Related Solutions

Write a Java Program to place a pizza ordering program. It creates a pizza ordered to...
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...
Java - Write a test program that creates an Account object with an account number of...
Java - Write a test program that creates an Account object with an account number of AC1111, a balance of $25,000, and an annual interest rate of 3.5. Use the withdraw method to withdraw $3,500, use the deposit method to deposit $3,500, and print the balance, the monthly interest, and the date when this account was created.
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date...
JAVA - Write a program that creates an ArrayList and adds an Account object, a Date object, a ClockWithAudio object, a BMI object, a Day object, and a FigurePane object. Then display all elements in the list. Assume that all classes (i.e. Date, Account, etc.) have their own no-argument constructor.
Write a program (in C, or Java, or C++, or C#) that creates three new threads...
Write a program (in C, or Java, or C++, or C#) that creates three new threads (besides the already existing main thread) and synchronizes them in such a way that each thread displays it's thread id in turn for 5 iterations. The output of the program should look like this: Thread 1 - iteration no. 1 Thread 2 - iteration no. 1 Thread 3 - iteration no. 1 Thread 1 - iteration no. 2 Thread 2 - iteration no. 2...
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...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a...
Using Java preferably with Eclipse Task: Write a program that creates a class Apple and a tester to make sure the Apple class is crisp and delicious. Instructions: First create a class called Apple The class Apple DOES NOT HAVE a main method Some of the attributes of Apple are Type: A string that describes the apple.  It may only be of the following types:  Red Delicious  Golden Delicious  Gala  Granny Smith Weight: A decimal value representing...
Write a Java program that creates an array with 20 random numbers between 1 and 100,...
Write a Java program that creates an array with 20 random numbers between 1 and 100, and passes the array to functions in order to print the array, print the array in reverse order, find the maximum element of the array, and find the minimum element of the array. The prototype of the methods: public static void printArray(int arr[]) public static void printArrayReverse(int arr[]) public static int searchMax(int arr[]) public static int searchMin(int arr[]) Sample output: Random Array: [17 67...
Write a Java program thatdoes the following jobs.Step1. Creates a Schooltable with name, score, rating, and...
Write a Java program thatdoes the following jobs.Step1. Creates a Schooltable with name, score, rating, and district.Step2. Reads data from theCSVfile(elementrayschool.csv)and insert the schoolsinto the table created in Step 1.Step3. Interact with the user, wheretheusercan select one of the following actions.-(Q) Quit: quit the program-(A) Add a school-(C) Calculate average rating-(S) Print a subset of the schools based on score-(D) Print a subset of the schools based on districtThe user can choose one of these actions bytyping Q,A,C, S, or...
Write a java program that creates a hashtable with 10 objects and 5 data members using...
Write a java program that creates a hashtable with 10 objects and 5 data members using mutator and accessor methods for each data member.
Give an example of a program in java that creates a GUI with at least one...
Give an example of a program in java that creates a GUI with at least one button and several textfields. Some of the textfields should be for input and others for output. Make the output textfields uneditable. When the button is clicked, the input fields should be read, some calculation performed and the result displayed in the output textfield(s).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT