// This program enhances our Receipt program using a cumulative sum. import java.util.*; public class Receipt2 { public static void main(String[] args) { Scanner console = new Scanner(System.in); int numPeople = getNumPeople(console); double subtotal = getSubtotal(console, numPeople); System.out.println(); results(subtotal); } // Asks how many people are on this check. public static int getNumPeople(Scanner console) { System.out.print("How many people ate? "); return console.nextInt(); } // Prompts for number of people and returns total meal subtotal. public static double getSubtotal(Scanner console, int numPeople) { double subtotal = 0.0; // cumulative sum for (int i = 1; i <= numPeople; i++) { System.out.print("Person #" + i + ": How much did your dinner cost? "); double personCost = console.nextDouble(); subtotal = subtotal + personCost; // add to sum } return subtotal; } // Calculates total owed, assuming 8% tax and 15% tip public static void results(double subtotal) { double tax = subtotal * .08; double tip = subtotal * .15; double total = subtotal + tax + tip; System.out.println("Subtotal: $" + subtotal); System.out.println("Tax: $" + tax); System.out.println("Tip: $" + tip); System.out.println("Total: $" + total); } }