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 ( Ask the customer the following Question using the message box then the summary of the order should show up in the console )

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

Here is the Code for PizzaOrder.java with all requried comments:

package pizzaorder;
import javax.swing.*; 
public class PizzaOrder {

        public static void main(String[] args) {
                JFrame frame=new JFrame();
                //Show welcome message
                JOptionPane.showMessageDialog(frame, "Welcome to _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ Pizza");

                //Shown input for name
                String input = JOptionPane.showInputDialog("Enter your first name:");
                System.out.println(input);
                //If name is not entered then exit
                if(input==null||input.isEmpty() || input.equalsIgnoreCase(""))
                        return;

                //Show options for Pizza sizes  
                String option = JOptionPane.showInputDialog("Pizza sizes (inches) Cost:\n" + 
                                " 1. 10”: $10.99 \n" + 
                                " 2. 12”: $12.99 \n" + 
                                " 3. 14”: $14.99 \n" + 
                                " 4. 16”: $16.99.\n"
                                + "What size pizza would you like?\n"
                                + "10, 12, 14, or 16 (enter the number only):");
                System.out.println(option);
                //if no option entered, exit then
                if(option==null|| option.isEmpty() || option.equalsIgnoreCase(""))
                        return;

                //Show type of crust options
                String typeOfCrust = JOptionPane.showInputDialog("What type of crust do you want?\n" + 
                                "(H)Hand-tossed\n" + 
                                "(T)Thin-crust\n" + 
                                "(D)Deepdish\n" + 
                                "(enter H, T, or D):");
                System.out.println(typeOfCrust);
                if(typeOfCrust==null ||typeOfCrust.isEmpty() || typeOfCrust.equalsIgnoreCase(""))
                        return;

                //Show message for toppings
                JOptionPane.showMessageDialog(frame," All pizzas come with cheese. Additional toppings are $1.25 each, choose from:\n"
                                + " Pepperoni, Sausage, Onion, Mushroom");
                //option for peperoni
                String peperoni=JOptionPane.showInputDialog( "Do you want Pepperoni? (Y/N):");
                System.out.println(peperoni);
                if(peperoni==null ||peperoni.isEmpty() || peperoni.equalsIgnoreCase(""))
                        return;
                
                //option for sousage
                String sousage=JOptionPane.showInputDialog("Do you want Sausage? (Y/N):");
                System.out.println(sousage);
                if(sousage.isEmpty() || sousage.equalsIgnoreCase(""))
                        return;

                //option for onion
                String onion=JOptionPane.showInputDialog("Do you want Onion? (Y/N):");
                System.out.println(onion);
                if(onion==null ||onion.isEmpty() || onion.equalsIgnoreCase(""))
                        return;

                //option for mushroom
                String mushroom=JOptionPane.showInputDialog(" Do you want Mushroom? (Y/N):");
                System.out.println(mushroom);

                if(mushroom==null ||mushroom.isEmpty() || mushroom.equalsIgnoreCase(""))
                        return;

                /*
                 * 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
                 */

                String order="Your order is as follows:\n";
                order+=option+"-intch Pizza\n";
                switch (typeOfCrust) {
                case "H":
                        order+="Hand-tossed crust";
                        break;
                case "T":
                        order+="Thin-crust";
                        break;
                case "D":
                        order+="Deepdish crust";
                        break;

                default:
                        break;
                }
                order+=" $ ";
                double cost=0.0;
                switch (option) {
                case "10":cost=10.99; break;
                case "12": cost=12.99;break;
                case "14": cost=14.99;break;
                case "16": cost=16.99;break;
                        
                default:
                        break;
                }
                order+= Double.toString(cost)+"\n";
                
                double costtopping=0.0;
                if(peperoni.equalsIgnoreCase("Y") || peperoni.equalsIgnoreCase("y")) {
                        costtopping+=1.25;
                        order+="\nPeperoni $ "+"1.25";
                }
                if(sousage.equalsIgnoreCase("Y") || sousage.equalsIgnoreCase("y")) {
                        costtopping+=1.25;
                        order+="\nSousage $ "+"1.25";
                }
                if(onion.equalsIgnoreCase("Y") || onion.equalsIgnoreCase("y")) {
                        costtopping+=1.25;
                        order+="\nOnion $ "+"1.25";
                }
                if(mushroom.equalsIgnoreCase("Y") || mushroom.equalsIgnoreCase("y")) {
                        costtopping+=1.25;
                        order+="\nOnion $ "+"1.25";
                }
                //sub total
                Double totalcost=cost+costtopping;
                
                order+="\nThe subtotal cost of your order is: $ "+Double.toString(totalcost);
                
                //tax calculation
                Double tax=(Double)((totalcost/100)*8.875);
                

                order+="\nThe tax is: $ "+ tax +" ----------------\n";
                
                //final amount calculation
                Double finalAmount=totalcost+tax;
                order+="total is: $ "+finalAmount; //13.33
                
                //reciept display
                JOptionPane.showMessageDialog(frame, order);
                
        }

}

Output:
UI Screens for all inputs and messages:


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...
IN JAVA write a program that creates an array of strings with 8 people in it....
IN JAVA write a program that creates an array of strings with 8 people in it. Second,  Assign a random rank between 1 to 8 to each of the players. The rankings do not change throughout the tournament. Finally, Sort the players based on the rankings and print the data (show rankings of players, in square brackets, at every step after they are ranked). USING JAVA COLLECTIONS IS NOT ALLOWED
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...
java please Write a program that creates an ArrayList and adds 5 circle objects to the...
java please Write a program that creates an ArrayList and adds 5 circle objects to the list , and display all elements in the list by invoking the object’s toString() method.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT