///* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ /** * This program allows the user to order a pizza * * @author Juan Carlos sanabria */ import java.util.Scanner; import java.text.DecimalFormat; public class PizzaOrder { public static void main (String [] args) { //TASK #5 Create a DecimalFormat object with 2 decimal places // You have to add code!!! DecimalFormat DollarFormat = new DecimalFormat("#0.00"); //Create a Scanner object to read input Scanner keyboard = new Scanner (System.in); String firstName; //user's first name boolean discount = false; //flag, true if user is eligible for discount int inches; //size of the pizza char crustType; //code for type of crust******* String crust = null; //name of crust double cost = 12.99; //cost of pizza****** final double TAX_RATE = .08; //sales tax rate double tax; //amount of tax char choice; //user's choice String input; //user input String toppings= ("With these Toppings\n"); int numberOfToppings=0; //number of toppings********* //prompt user and get first name System.out.println("Welcome to Mike and Diane's Pizza\n"); System.out.print("Enter your first name:"); firstName = keyboard.nextLine(); //determine if user is eligible for discount by //having the same first name as one of the owners //ADD LINES HERE FOR TASK #1 if(firstName.compareToIgnoreCase("Mike")==0|| firstName.compareToIgnoreCase("Diane")==0) discount=true; //prompt user and get pizza size choice System.out.println("\nPizza Size (inches) Cost\n"); System.out.println(" 10 $10.99"); System.out.println(" 12 $12.99"); System.out.println(" 14 $14.99"); System.out.println(" 16 $16.99\n"); System.out.println("What size pizza would you like?"); System.out.print("10, 12, 14, or 16 (enter the number only):\n "); inches = keyboard.nextInt(); //set price and size of pizza ordered 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 {System.out.println(inches+" is not a valid size-you will recieve a 12\" pizza"); inches=12; cost=12.99; } System.out.println("The size of your pizza is" + " " + inches+" inches"); System.out.println("The cost of your pizza is" + " " + cost); //ADD LINES HERE FOR TASK #2 //consume the remaining newline character keyboard.nextLine(); //prompt user and get crust choice System.out.println("What type of crust do you want? "); System.out.print("(H)Hand-tossed, (T) Thin-crust, or " + "(D) Deep-dish (enter H, T, or D): "); input = keyboard.nextLine(); crustType = input.charAt(0); choice=crustType; //set user's crust choice on pizza ordered //ADD LINES FOR TASK #3....sWITCH sTATEMENT switch(crustType) {default: System.out.println(crustType+" is not a choice-you will get Hand-tossed"); //crustType='h'; case 'H': case 'h': crust="Hand-tossed"; break; case 'T': case 't': crust="Thin-crust"; break; case 'D': case 'd': crust="Deep-dish "; break; } System.out.println("You ordered a"+" "+crust+" "+"pizza\n"); //prompt user and get topping choices one at a time System.out.println("All pizzas come with cheese.\n"); System.out.println("Additional toppings are $1.25 each," +" choose from"); System.out.println("Pepperoni, Sausage, Onion, Mushroom"); //if topping is desired, //add to topping list and number of toppings System.out.print("Do you want Pepperoni? (Y/N): "); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Pepperoni "; } System.out.print("Do you want Sausage? (Y/N): "); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Sausage "; } System.out.print("Do you want Onion? (Y/N): "); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Onion "; } System.out.print("Do you want Mushroom? (Y/N): "); input = keyboard.nextLine(); choice = input.charAt(0); if (choice == 'Y' || choice == 'y') { numberOfToppings += 1; toppings = toppings + "Mushroom "; } //add additional toppings cost to cost of pizza cost = cost + (1.25*numberOfToppings); //display order confirmation System.out.println(); System.out.println("Your order is as follows: "); System.out.println(inches + " inch pizza"); System.out.println(crust + " crust"); System.out.println(toppings); //Apply discount if elible //ADD LINES FOR TASK #4 HERE if(discount) {System.out.println("You are eligible for a $2 discount"); cost-=2; } //EDIT PROGRAM FOR TASK #5 //SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES System.out.println("The cost of your order is: $" +DollarFormat.format(cost)); //calculate and display tax and total cost tax = cost * TAX_RATE; System.out.println("The tax is: $" + DollarFormat.format(tax)); System.out.println("The total due is: $" + DollarFormat.format(tax+cost)); System.out.println("Your order will be ready for pickup in 30 minutes."); } } //