// Helene Martin, CSE 142 // Calculate total owed, assuming 8% tax / 15% tip // goal: demonstrate using returns to structure a program well // demonstrate using a cumulative sum with Scanner input import java.util.*; public class Receipt { public static void main(String[] args) { Scanner console = new Scanner(System.in); double subtotal = getSubtotal(console); double tipAmount = getTip(console); reportResults(subtotal, tipAmount); } // Prompts user for meal costs and returns subtotal. 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 was your meal? "); double price = console.nextDouble(); subtotal = subtotal + price; } return subtotal; } // Prompts user for tip amount and returns it. public static double getTip(Scanner console) { System.out.print("What percent tip will you leave? "); double tipAmount = console.nextDouble(); return tipAmount; } // Prints subtotal, tax, tip and total based on subtotal and tip amount. public static void reportResults(double subtotal, double tipAmount) { double tax = subtotal * .08; double tip = subtotal * tipAmount / 100; 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); } }