Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I can not get my code to compile, can someone please help? its in java. import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Pizzeria {

I can not get my code to compile, can someone please help? its in java.

import java.util.ArrayList;

import java.util.Arrays;

import java.util.Scanner;

public class Pizzeria {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

// variables

String userName;

String pizzaName;

double diameter;

double area = 0;

char totalDisplay = 0;

char pepperoniChoice;

double total = 0.0;

int numPizzas = 0;

final double cheesePerInch = 0.0272;

final double saucePerInch = 0.0316;

final double doughPerInch = 0.0228;

final double toppingPerInch = 0.0284;

String[] pizzaNames = new String[50]; // Array to store pizza names

double[] pizzaPrices = new double[50]; // Array to store pizza prices

//array list of valid toppings

String[] validToppings = {"Pepperoni", "Mushroom", "Chicken", "Ham", "Pineapple", "Sausage", "Basil", "Olive"};

//user intro

System.out.println("Welcome to Adkins Pizzeria!");

System.out.println("Can I have your name please?");

userName = scnr.nextLine();

System.out.println("Ok, let's start your order, " + userName + ".");

//Menu

while (true) {

System.out.println("Here is what you can do next:");

System.out.println("MENU");

System.out.println("a - Add a pizza");

System.out.println("t - Print the total");

System.out.println("r - Read the order");

System.out.println("q - Quit");

System.out.println("Please make a selection:");

String selection = "";

//read users selection and store it into variable for switch statement

selection = scnr.nextLine();

switch (selection) {

case "a":

numPizzas++;

System.out.println(" What would you like to name pizza number " + numPizzas + "?");

pizzaName = scnr.nextLine();

System.out.println("What size would you like " + pizzaName + " to be?");

System.out.println("We can handle pizzas between 8 and 48 inches.");

diameter = scnr.nextDouble();

while (diameter < 8 || diameter > 48) {

System.out.println("Invalid diameter. Please enter a value between 8 and 48 inches.");

diameter = scnr.nextDouble();

}

scnr.nextLine(); // Consume the remaining newline character

System.out.println("How many toppings would you like on this pizza?");

System.out.println("You can have between 0-8 toppings.");

int numToppings = scnr.nextInt();

while (numToppings < 0 || numToppings > 8) {

System.out.println("Invalid number of toppings. Please enter a value between 0 and 8.");

numToppings = scnr.nextInt();

}

scnr.nextLine(); // Consume the remaining newline character

ArrayList toppings = new ArrayList<>(numToppings);

for (int j = 0; j < numToppings; j++) {

System.out.println("What topping would you like?");

System.out.println("Your options are: Pepperoni, Mushroom, Chicken, Ham, Pineapple, Sausage, Basil, Olive.");

String topping = scnr.nextLine();

while (!Arrays.asList(validToppings).contains(topping)) {

System.out.println("Invalid topping. Your options are: Pepperoni, Mushroom, Chicken, Ham, Pineapple, Sausage, Basil, Olive.");

topping = scnr.nextLine();

}

}

scnr.nextLine(); // Consume the remaining newline character

System.out.println("How many toppings would you like on this pizza?");

System.out.println("You can have between 0-8 toppings.");

int numToppings = scnr.nextInt();

while (numToppings < 0 || numToppings > 8) {

System.out.println("Invalid number of toppings. Please enter a value between 0 and 8.");

numToppings = scnr.nextInt();

}

scnr.nextLine(); // Consume the remaining newline character

String[] toppings = new String[numToppings];

for (int j = 0; j < numToppings; j++) {

System.out.println("What topping would you like?");

System.out.println("Your options are: Pepperoni, Mushroom, Chicken, Ham, Pineapple, Sausage, Basil, Olive.");

String topping = scnr.nextLine();

while (!Arrays.asList(validToppings).contains(topping)) {

System.out.println("Invalid topping. Your options are: Pepperoni, Mushroom, Chicken, Ham, Pineapple, Sausage, Basil, Olive.");

topping = scnr.nextLine();

}

toppings[j] = topping;

System.out.println("Chosen topping " + topping + " added.");

System.out.println();

}

double pizzaCost = Math.PI * Math.pow(diameter / 2.0, 2) * (cheesePerInch + saucePerInch + doughPerInch + numToppings * toppingPerInch);

total += pizzaCost;

System.out.print("You have ordered " + pizzaName + " with toppings: ");

for (int j = 0; j < numToppings; j++) {

System.out.print(toppings[j] + ", ");

}

System.out.printf("This pizza costs $%.2f ", pizzaCost);

// store pizza name and cost in arrays

pizzaNames[numPizzas - 1] = pizzaName;

pizzaPrices[numPizzas - 1] = pizzaCost;

break;

case "t":

System.out.printf("The total cost of your order is $%.2f ", total);

break;

case "r":

System.out.println("Your order:");

for (int i = 0; i < numPizzas; i++) {

System.out.printf("%d. %s: $%.2f ", i + 1, pizzaNames[i], pizzaPrices[i]);

}

break;

case "q":

System.out.println("Thank you for your order! Goodbye!");

System.exit(0);

break;

default:

System.out.println("Invalid selection. Please try again.");

break;

}

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions