PIZZA ORDER FRAME PROGRAM Write a frame with components for an order form for a
ID: 3688477 • Letter: P
Question
PIZZA ORDER FRAME PROGRAM
Write a frame with components for an order form for a pizza (see image of frame). The frame should be able to run itself and include an appropriate title bar. All your frame components will have an appropriate pizza colored background and foreground. The purpose of this exercise is to show layouts and panels with different kinds of events. You will use a border layout with panels to divide the frame into 3 sections - top, middle, and bottom. All of the sections will use the panels with a grid layout for the multiple components.
The top section will have the centered title telling the name of the company (in a larger and different style typeface) and underneath it separate centered instructions to choose your pizza size and toppings.
The middle section will have four radio buttons in a button group: small - $7, medium - $9, large - $11, and extra large - $13. The right side of the middle section will also have a list object for the available toppings - Eggplant, Green Peppers, Hot Peppers, Pepperoni, Sausage, Mushrooms, and Anchovies (of which they can pick as many as they want from 0 - 7). Each topping will add $1 to the total price. Before they pick any pizza size or toppings, there should be no size or toppings selected.
The bottom section will have first a label saying APrice of your pizza is $0.00", and then to the right of the price label will be a checkbox promoting a $5.00 side order of hot wings. The price of the pizza will be updated as they pick different sizes or toppings, also in a larger point size and different typeface with the price formatted in Currency.
Use the setSize() for the frame, but be careful of the sizing, components tend to fill up unused areas in a border layout. For the list, make sure you can see all items but don't let there be any extra space, just resize the frame so everything fits and there is no extra space and don=t let the user change the frame=s size on you.
As soon as the user clicks on a new size, topping, or the wings check box, update the price immediately. Let the user make changes to the form as often as they want, seeing the updated price immediately. Have a price variable for the size price (which could include the extra wings price), a price variable for the topping price, and a total price. Only calculate and update what they change (ex. if they add a topping, the size does not have to be recalculated).
When they pick a size radio button, check to see which one they picked and change the size price (you will be an ItemListener). Then check to see if the wings check box is checked off, if so then add the $5.00 to the size price. Add to this size price the topping price, format the final price to Currency and update the price label. When they pick a topping or toppings (hold control key down for multiple toppings), calculate the topping price (add $1.00 for each topping they picked) (you will be a ListSelectionListener). Add to this the size price, format the final price to Currency, and update the price label.
1st Run:
Large Pizza with Eggplant and Hot Peppers, with a side order of wings.
2nd Run:
Medium Pizza with Green Peppers, Pepperoni, and Mushrooms, without a side order of wings.
Save the frame class code with documentation - full 4-5 line paragraph describing the frame and at least 5 documentation lines throughout the code. Run with each of the two runs, each time saving a picture of the actual frame results (they can be saved together in the same file as a .jpg). You can copy them with <alt><ptrscr> (just active frame) and paste both pictures into Paint for saving as a .jpg file. Submit both files (.java java code and .jpg output image of the two frame images).
Explanation / Answer
public static void main(String[] args) { DecimalFormat df = new DecimalFormat("#.##"); Scanner keyboard = new Scanner(System.in); // Variables String firstName; // first name of user char crustType; String crust; // name of crust int inches; // pizza size double cost = 0.0; // pizza cost final double taxRate = 0.08; // amount tax owed double tax; // tax amount double total; // total of pizza + toppings double lastTotal; // total of everything int numberOfToppings = 0; String toppings = "Cheese"; // Prompts for name & determines discount System.out.println("Enter your name: "); firstName = keyboard.nextLine(); //Prompts for distance double distance = 0; double deliveryfee = 0; System.out.println("Please enter total distance in miles from pizza shop (0 for in store pickup):"); distance = keyboard.nextDouble(); if (distance == 0) { deliveryfee = 0; System.out.println("There is no delivery fee."); } else if (distance > 1) { deliveryfee = ((distance * 0.5) + 2); System.out.println("Your delivery fee is: $" + df.format(deliveryfee)); } else if (distance > 0) { deliveryfee = 2.00; System.out.println("Your delivery fee is: $" + df.format(deliveryfee)); } // Prompts for pizza size System.out.print("What size of pizza would you like (diameter in inches)? (10, 12, 14, or 16) "); inches = keyboard.nextInt(); if (inches == 10) { cost = 10.99; } else if (inches == 12) { cost = 12.99; } else if (inches == 14) { cost = 14.99; } else if (inches == 16) { cost = 16.99; } else if (inches != 10 && inches != 12 && inches != 14 && inches != 16) { System.out.println("The number you have entered is illegal, your pizza size will be set to 12 inches. "); cost = 12; } keyboard.nextLine(); // Prompts user for type of crust System.out.print("What type of crust do you want? (H)and-Tossed, (T)hin-crust, or (D)eep-dish (enter H, T, or D,): "); crustType = keyboard.nextLine().charAt(0); if (crustType == 'H' || crustType == 'h') { crust = "Hand-Tossed"; } else if (crustType == 'T' || crustType == 't') { crust = "Thin-Crust"; } else if (crustType == 'D' || crustType == 'd') { crust = "Deep-Dish"; } else if (crustType != 'H' && crustType != 'h' && crustType != 'T' && crustType != 't' && crustType != 'D' && crustType != 'd') { System.out.println("The crust type you have entered is illegal, your crust type will be set to hand-tossed. "); } crust = "Hand-Tossed"; // Prompts user for additonal toppings System.out.println("All pizzas come with cheese."); System.out.println("Additional toppings are $1.25 each, choose from Pepperoni or Sausage."); // Pepperoni System.out.println("Do you want Pepperoni? (Y/N)"); numberOfToppings = keyboard.nextLine().charAt(0); if (numberOfToppings == 'Y' || numberOfToppings == 'y') { numberOfToppings = numberOfToppings + 1; toppings = toppings + " and Pepperoni"; } else { } //Sausage System.out.println("Do you want Sausage? (Y/N)"); numberOfToppings = keyboard.nextLine().charAt(0); if (numberOfToppings == 'Y' || numberOfToppings == 'y') { numberOfToppings = numberOfToppings + 1; toppings = toppings + " and Sausage"; } else { } // Calculations System.out.println(cost); System.out.println(numberOfToppings); System.out.println(deliveryfee); total = (cost) + (numberOfToppings * 1.25) + (deliveryfee); tax = total * taxRate; lastTotal = total * (1 + taxRate); // Payment Confirmation System.out.println(firstName + ", here is your order:"); System.out.println(inches + " inch pizza"); System.out.println(crust + ", " + toppings); System.out.println("Order Cost: $" + df.format(total)); System.out.println("Tax: $" + df.format(tax)); System.out.println("Total Due: $" + df.format(lastTotal)); }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.