Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

import java.util.

Scanner;

public class CashRegister {


public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

String[] mainDishes = {"None", "Pizza ($7.00)", "Burger ($5.50)", "Pasta


($6.50)"};
double[] mainDishPrices = {0.0, 7.0, 5.5, 6.5};

String[] sideDishes = {"None", "Fries ($2.50)", "Salad ($3.00)", "Onion


Rings ($3.50)"};
double[] sideDishPrices = {0.0, 2.5, 3.0, 3.5};

String[] drinks = {"None", "Water ($1.00)", "Soda ($2.00)", "Juice


($3.00)"};
double[] drinkPrices = {0.0, 1.0, 2.0, 3.0};

String[] desserts = {"None", "Ice Cream ($4.00)", "Cake ($5.00)"};


double[] dessertPrices = {0.0, 4.0, 5.0};

System.out.println("Welcome to House of Delicious! Let me take your


order.");

// Choose main dish


System.out.println("Please choose a main dish:");
for (int i = 0; i < mainDishes.length; i++) {
System.out.println(i + ") " + mainDishes[i]);
}
int mainChoice = scanner.nextInt();

// Choose side dish


System.out.println("Please choose a side dish:");
for (int i = 0; i < sideDishes.length; i++) {
System.out.println(i + ") " + sideDishes[i]);
}
int sideChoice = scanner.nextInt();

// Choose drink
System.out.println("Please choose a drink:");
for (int i = 0; i < drinks.length; i++) {
System.out.println(i + ") " + drinks[i]);
}
int drinkChoice = scanner.nextInt();

// Choose dessert
System.out.println("Please choose a dessert:");
for (int i = 0; i < desserts.length; i++) {
System.out.println(i + ") " + desserts[i]);
}
int dessertChoice = scanner.nextInt();

// Calculate subtotal
double subtotal = mainDishPrices[mainChoice] + sideDishPrices[sideChoice] +
drinkPrices[drinkChoice] + dessertPrices[dessertChoice];

// Calculate tax (13%)


double tax = subtotal * 0.13;
// Calculate combo discount
double comboDiscount = 0.0;
if (mainChoice != 0 && sideChoice != 0 && drinkChoice != 0) {
double comboSubtotal = mainDishPrices[mainChoice] +
sideDishPrices[sideChoice] + drinkPrices[drinkChoice];
comboDiscount = comboSubtotal * 0.1;
}

// Calculate total
double total = subtotal + tax - comboDiscount;

// Print receipt
System.out.println("Order complete!");
if (mainChoice != 0) {
System.out.println(mainDishes[mainChoice]);
}
if (sideChoice != 0) {
System.out.println(sideDishes[sideChoice]);
}
if (drinkChoice != 0) {
System.out.println(drinks[drinkChoice]);
}
if (dessertChoice != 0) {
System.out.println(desserts[dessertChoice]);
}
System.out.printf("Subtotal: $%.2f\n", subtotal);
System.out.printf("Tax: $%.2f\n", tax);
System.out.printf("Combo Discount: -$%.2f\n", comboDiscount);
System.out.printf("Total: $%.2f\n", total);

scanner.close();
}
}

You might also like