package lab_3;
/**
This program allows the user to order a pizza
*/
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
//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
double inches; //size of the pizza
char crustType; //code for type of crust
//No need for this line String crust = "Hand-tossed"; //name of crust***************
double cost; //12.99; //cost of the pizza***************
double toppingCost;
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"); //list of toppings
double numberOfToppings = 0; //number of toppings
//prompt user and get first name
System.out.println("Welcome to Mike and Diane's Pizza\n");
System.out.println("Enter your first name: ");
firstName = keyboard.nextLine();
System.out.println("Hello "+" "+ firstName+" \n");
//determine if user is eligible for discount by
//having the same first name as one of the owners
//ADD LINES HERE FOR TASK #1
//prompt user and get pizza size choice
System.out.println("Pizza Size (inches) Cost");
System.out.println("We have a varity of Pizzia sizes to choice from");
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)
System.out.println("Cost 10.99\n");
else if (inches==12)
System.out.println("Cost 12.99\n");
else if (inches==14)
System.out.println("Cost 14.99\n");
else if (inches==16)
System.out.println("Cost 16.99\n");
keyboard.nextLine();
//ADD LINES HERE FOR TASK #2
//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): \n");
input = keyboard.nextLine();
crustType = Character.toUpperCase(input.charAt(0)); // I added this line. if user enters lower case******
// it is automaticly converted to uppercase***********
//I used the else if statement to set user's crust choice on pizza ordered****************
if (crustType=='H')
System.out.println("Hand-tossed\n");
else if(crustType=='T')
System.out.println("Thin Crust\n");
else if(crustType=='D')
System.out.println("Deep Pan\n");
else
crustType=keyboard.next();
System.out.println("Invalid Selection\n");
//ADD LINES FOR TASK #3
//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\n";
}
//add additional toppings cost to cost of pizza
cost = (1.25*numberOfToppings);
System.out.println(numberOfToppings);
System.out.println();
System.out.println();
//display order confirmation
System.out.println();
System.out.println("Your order is as follows:\n ");
System.out.println(inches + " inch pizza\n");
System.out.println(crustType + " crust\n"); //changed
System.out.println(toppings);
//apply discount if user is elibible
//ADD LINES FOR TASK #4 HERE
//calculate and display tax and total cost
toppingCost= 1.25*numberOfToppings;
System.out.println("Topping cost "+ toppingCost);
tax = cost * TAX_RATE;
System.out.println("The tax is: $" + tax);
System.out.println("The total due is: $" + (tax+cost));
//EDIT PROGRAM FOR TASK #5
//SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES
cost=(inches+toppingCost+tax);
System.out.println("The cost of your order is: $" + cost);
// Order completed
System.out.println("Your order will be ready for pickup in 30 minutes.");
}
}