Professional Documents
Culture Documents
Cash Register
Cash Register
Scanner;
// 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 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();
}
}