// CSE 142 Lecture 9 // Advanced if/else, Cumulative algorithms import java.util.*; // For Scanner // Prints a restaurant receipt. public class Receipt { public static void main(String[] args) { // Calculate total owed, assuming 8% tax / 15% tip Scanner console = new Scanner(System.in); double subtotal = getSubtotal(console); reportBill(subtotal); } // Gets the total paid for dinner from the user. public static double getSubtotal(Scanner console) { System.out.print("How many people ate? "); int people = console.nextInt(); double subtotal = 0; for (int i = 1; i <= people; i++) { System.out.print("Person #" + i + " How much did your dinner cost? "); subtotal += console.nextDouble(); } return subtotal; } // Prints the bill including tax, tip, and total. public static void reportBill(double subtotal) { double tax = subtotal * .08; double tip = subtotal * .15; double total = subtotal + tip + tax; System.out.printf("Subtotal: $%.2f\n", subtotal); System.out.printf("Tax: $%.2f\n", tax); System.out.printf("Tip: $%.2f\n", tip); System.out.printf("Total: $%.2f\n", total); } }