Respuesta :
Answer:
File: PizzaOrder.java
import java.util.Scanner;
public class PizzaOrder
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String firstName;
boolean discount = false;
int inches;
char crustType;
String crust; // MODIFIED
double cost; // MODIFIED
final double TAX_RATE = 0.08;
double tax;
char choice;
String input;
String toppings = "Cheese ";
int numberOfToppings = 0;
System.out.println("Welcome to Mike and Diane's Pizza");
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
// ADD LINES HERE FOR TASK #1
if(firstName.equalsIgnoreCase("Mike") || firstName.equalsIgnoreCase("Diane"))
discount = true;
System.out.println("Pizza Size (inches) Cost");
System.out.println(" 10 $10.99");
System.out.println(" 12 $12.99");
System.out.println(" 14 $14.99");
System.out.println(" 16 $16.99");
System.out.println("What size pizza would you like?");
System.out.print("10, 12, 14, or 16 (enter the number only): ");
inches = keyboard.nextInt();
// ADD LINES HERE FOR TASK #2
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("The user input was not one of the choices, so a 12 inch pizza will be made.");
cost = 12.99;
}
keyboard.nextLine();
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);
// ADD LINES FOR TASK #3
switch(crustType)
{
case 'H':
case 'h':
crust = "Hand-tossed";
break;
case 'T':
case 't':
crust = "Thin-crust";
break;
case 'D':
case 'd':
crust = "Deep-dish";
break;
default:
System.out.println("The user input was not one of the choices, so a Hand-tossed crust will be made.");
crust = "Hand-tossed";
}
System.out.println("All pizzas come with cheese.");
System.out.println("Additional toppings are $1.25 each, choose from:");
System.out.println("Pepperoni, Sausage, Onion, Mushroom");
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 ";
}
cost = cost + (1.25 * numberOfToppings);
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);
// ADD LINES FOR TASK #4 HERE
if(discount)
cost = cost - 2.0;
// EDIT PROGRAM FOR TASK #5
// SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES
System.out.printf("The cost of your order " + "is: $%.2f\n", cost);// MODIFIED
tax = cost * TAX_RATE;
System.out.printf("The tax is: $%.2f\n", tax);// MODIFIED
System.out.printf("The total due is: $%.2f\n", (tax + cost));// MODIFIED
System.out.println("Your order will be ready for pickup in 30 minutes.");
}
}
Explanation: