Question
For my program it is call pizza order and I am having trouble figuring out how to add a code to add multiple toppings with
For my program it is call pizza order and I am having trouble figuring out how to add a code to add multiple toppings with out using arrays, code is below.
import java.util.Scanner;
public class PizzaOrder { public static void main(String[] args){ Scanner keyboard = new Scanner(System.in); double orderTotal = 0.0; System.out.println("How many pizzas do you want to order today?"); int numPizzas = keyboard.nextInt(); for (int i = 1; i <= numPizzas;i++){ System.out.println("Pizzas " + i + ":"); System.out.println("What size would you like? (Small,Medium,Large)"); String size = keyboard.next(); double sizePrice = 0.0; if (size.equalsIgnoreCase("Small")){ sizePrice = 8.0; }else if (size.equalsIgnoreCase("Medium")){ sizePrice = 12.0; }else if (size.equalsIgnoreCase("Large")){ sizePrice = 16.0; } System.out.println("What is your crust preference? (Regular, Thin, Pan Stuffed)"); String crust = keyboard.next(); double crustPrice = 0.0; if (crust.equalsIgnoreCase("thin")){ crustPrice = 2.0; }else if(crust.equalsIgnoreCase("pan")){ crustPrice = 3.0; }else if(crust.equalsIgnoreCase("stuffed")){ crustPrice = 3.5; } System.out.println("Do you want to add Double cheese, enter y for yes: ");//, Pepperoni, Sausage, Mushrooms, Spinach )"); String toppings = keyboard.next(); double toppingsPrice = 0.0; if(toppings.equalsIgnoreCase("y")){ toppingsPrice += 1.0; } if(toppings.equalsIgnoreCase("no" )){ toppingsPrice += 2.0; } System.out.println("What toppings would you like? (Double cheese, Pepperoni, Sausage, Mushrooms, Spinach )"); toppings = keyboard.next(); if(toppings.equalsIgnoreCase("pepperoni")){ toppingsPrice += 2.0; } double pizzaPrice = sizePrice + crustPrice + toppingsPrice; System.out.println("Pizza" +i+":" +size+ ""+crust+ "crust with" +toppings+ "-$" +pizzaPrice); orderTotal += pizzaPrice; } System.out.println("Number of pizzas ordered: "+numPizzas); System.out.println("Order total: $" + orderTotal); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started