In summary my program is not accounting for each additional topping that is included on the pizza and then adding 1.25 to the base cost as expected and then appropriately computing the tax and finally producing the overall total. My brain is in a haze trying to figure it out. Any pointers?
I'm stumped on what could even be a potential solution so I'm not quite sure what to try.
import java.util.Scanner;
public class PizzaOrder {
public static void main(String[] args) {
//Declared variables
String firstName; // First name of user
char crustType; // Type of crust
String crustName; // Name of crust
int inches; // Pizza size
final double Tax_Rate = 0.08; // Tax Rate
double baseCost = 0.0; // Cost of pizza without tax and additional toppings.
double total; // base cost plus the toppings
double overallTotal; // Total cost including toppings and tax
double tax; // Tax amount
String toppings = "Cheese"; // Toppings list
String choice;
int numberOfToppings = 0; // Toppings counter
// Create Scanner object
Scanner keyboard = new Scanner(System.in);
//Prompt and get the users first name
System.out.println("Welcome to Mike and Diane's Pizza.");
System.out.print("Enter your first name: ");
firstName = keyboard.nextLine();
//Prompt and get pizza size
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.print("Enter the size of the pizza you would like: ");
inches = keyboard.nextInt();
keyboard.nextLine(); //Consuming end of line character
if(inches == 10) {
baseCost = 10.99;
}
else if(inches == 12) {
baseCost = 12.99;
}
else if(inches == 14) {
baseCost = 14.99;
}
else if(inches == 16) {
baseCost = 16.99;
}
else if(inches != 10 && inches != 12 && inches != 14 && inches != 16) {
System.out.print("You have entered an invalid choice. The pizza size" +
" will be set to 12 inches. ");
}
// Prompt and get crust choice
System.out.print("Enter the type of crust you would like. " +
" (H)and-Tossed, (T)hin-Crust, or (D)eep-Dish: ");
crustName = keyboard.nextLine();
crustType = crustName.charAt(0);
// Output if the user selects Hand-Tossed
if(crustType == 'H' || crustType == 'h') {
crustName = "Hand-Tossed";
System.out.println("You selected Hand-Tossed pizza. ");
}
// Output if the user selects Thin-Crust.
else if(crustType == 'T' || crustType == 't') {
crustName = "Thin-Crust";
System.out.println("You selected Thin Crust pizza. ");
}
// Output if the user selects Deep-dish.
else if(crustType == 'D' || crustType == 'd') {
crustName = "Deep-dish";
System.out.println("You selected Deep-Dish pizza. ");
}
// Otherwise print out the default pizza type.
else {
System.out.print("You have entered an invalid choice. The crust type" +
"will be set to Hand-Tossed. ");
}
// Display message about toppings and additional cost
System.out.println("All pizzas come with cheese.");
System.out.println("Additional toppings are $1.25 each. Please choose" +
" from Pepperoni, Onion, Sausage, and Mushroom. ");
// Prompt and get topping choices one at a time. If topping is desired, add
// name to topping list and increment number of toppings.
System.out.print("Would you like pepperoni added? (Y/N): ");
choice = keyboard.nextLine();
if (choice.equals("Y") || choice.equals('y')) {
numberOfToppings = numberOfToppings + 1;
toppings = toppings + " and pepperoni.";
}
else {
numberOfToppings = 0;
}
//Prompt for sausage and store in numberOfToppings
System.out.print("Would you like sausage added? (Y/N): ");
choice = keyboard.nextLine();
if (choice.equals("Y") || choice.equals('y')) {
numberOfToppings = numberOfToppings + 1;
toppings = toppings + " and sausage.";
}
else {
numberOfToppings = 0;
}
//prompt for onion and store in numberOfToppings
System.out.print("Would you like onion added? (Y/N): ");
choice = keyboard.nextLine();
if (choice.equals("Y") || choice.equals('y')) {
numberOfToppings = numberOfToppings + 1;
toppings = toppings + " and onion.";
}
else {
numberOfToppings = 0;
}
//prompt for mushroom and store in numberOfToppings
System.out.print("Would you like mushroom added? (Y/N): ");
choice = keyboard.nextLine();
if (choice.equals("Y") || choice.equals('y')) {
numberOfToppings = numberOfToppings + 1;
toppings = toppings + " and mushroom.";
}
else {
numberOfToppings = 0;
}
//Calculation of cost
total = ((baseCost) + (numberOfToppings * 1.25));
tax = total * Tax_Rate;
overallTotal = total * (1 + Tax_Rate);
// Payment Confirmation
System.out.println(firstName + ", here is your order:");
System.out.println(inches + " inch pizza");
System.out.println(crustName + ", " + toppings);
System.out.println("The cost of your order is: $" + (total));
System.out.println("The tax is: $" + (tax));
System.out.println("The overall total due is: $" + (overallTotal));
}
}
The expected output would take the base cost, add 1.25 times whatever number of toppings, compute the tax and then add the tax to the cost that includes the toppings. Can anyone help please?