Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with this problem: Develop an application using the User Interface a

ID: 3770557 • Letter: I

Question

I need help with this problem:

Develop an application using the User Interface and item/price chart below to calculate the price of pizza based on its size (small, medium, and large) and toppings (Sausage, Olives, Pepperoni, Mushrooms, Salami, and Anchovies)

Item                           Price

Small pizza             $6.99

Medium pizza          $8.99

Large pizza            $10.99

Sausage                 $1.49

Pepperoni              $1.49

Salami                   $1.49

Olives                    $0.99

Mushrooms           $0.99

Anchovies            $0.99

Explanation / Answer

import java.util.Scanner;
import java.text.DecimalFormat;
public class PizzaOrder
{
public static void main (String [] args)
{
Scanner keyboard = new Scanner (System.in);
Pizza order = new Pizza ();
String firstName;
boolean discount = false;
int inches;
char crustType;
double cost;
final double TAX_RATE = .08;
double tax;
char choice;
String input;
String toppings = "Cheese ";
int numberOfToppings = 0;
System.out.println("Welcome to *** and " + "*** Pizza");
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
if ( (firstName.equalsIgnoreCase("Mike")) || (firstName.equalsIgnoreCase("***")) || (firstName.equalsIgnoreCase("***")) )
{
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();
if (inches == 10)
{ order.setCost(-2);
}
else if (inches == 14)
{
order.setCost(+2);
}
else if (inches == 16)
{
order.setCost(+4);
}
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 = Character.toUpperCase(input.charAt(0));
switch (crustType)
{
case 'H': order.setCrust("Hand-tossed"); break;
case 'D': order.setCrust("Deep-dish"); break;
case 'T': order.setCrust("Thin-crust"); break;
default: order.setCrust("Invalid selection: Using Hand-tossed"); break;
}
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 = Character.toUpperCase(input.charAt(0));
if (choice == 'Y')
{
numberOfToppings += 1;
toppings = toppings + "Pepperoni ";
}
System.out.print("Do you want Sausage? (Y/N): ");
input = keyboard.nextLine();
choice = Character.toUpperCase(input.charAt(0));
if (choice == 'Y')
{
numberOfToppings += 1;
toppings = toppings + "Sausage ";
}
System.out.print("Do you want Onion? (Y/N): ");
input = keyboard.nextLine();
choice = Character.toUpperCase(input.charAt(0));
if (choice == 'Y')
{
numberOfToppings += 1;
toppings = toppings + "Onion ";
}
System.out.print("Do you want Mushroom? (Y/N): ");
input = keyboard.nextLine();
choice = Character.toUpperCase(input.charAt(0));
if (choice == 'Y')
{
numberOfToppings += 1;
toppings = toppings + "Mushroom ";
}
order.setNumToppings(numberOfToppings);
order.setToppingList(toppings);
order.setCost(1.25*numberOfToppings);
System.out.println();
System.out.println("Your order is as follows: ");
System.out.println(order.getSize() + " inch pizza");
System.out.println(order.getCrust() + " crust");
System.out.println(order.getToppingList());
cost = order.getCost();
if (discount == true)
{
System.out.println("You get a discount!");
order.setCost(-2);
cost = order.getCost();
}
DecimalFormat df = new DecimalFormat("##.00");
System.out.println("The cost of your order is: $" + df.format(cost));
tax = (cost * TAX_RATE);
System.out.println("The tax is: $" + df.format(tax));
System.out.println("The total due is: $" + df.format((tax+cost)));
System.out.println("Your order will be ready for pickup in 30 minutes.");
}
}