// Helene Martin, CSE 142 // Calculate total owed at a restaurant. Asks the user for size of // party, meal costs and tip amount. // Waiters at this restaurant have strong reactions to tip amounts. import java.util.*; public class Receipt { public static final double TAX = .08%; public static void main(String[] args) { Scanner s = new Scanner(System.in); double subtotal = getSubtotal(s); double tax = subtotal * TAX; double tipPercent = getTip(s); double tip = subtotal * tipPercent / 100; double total = tax + tip + subtotal; reportResults(subtotal, tax, tip); reportWaiter(total, tipPercent); } // asks the user for a tip percentage public static double getTip(Scanner s) { System.out.print("What percent tip will you leave? "); double tip = s.nextDouble(); return tip; } // asks the user how many people ate and returns the sum // of their meal values public static double getSubtotal(Scanner s) { System.out.print("How many people ate? "); int people = s.nextInt(); double subtotal = 0; for(int i = 1; i <= people; i++) { System.out.print("Person #" + i + ": how much was your meal? "); double cost = s.nextDouble(); subtotal += cost; } return subtotal; } // prints all calculated values to the console public static void reportResults(double subtotal, double tax, double tip) { System.out.println("Subtotal: $" + subtotal); System.out.println("Tax: $" + tax); System.out.println("Tip: $" + tip); System.out.println("Total: $" + (subtotal + tip + tax)); } // prints what the waiter does to the console based on total and tip percentage public static void reportWaiter(double total, double tipPercent) { if(tipPercent < 15) { System.out.println("The waiter spits in your food."); } else if(tipPercent < 17 && total < 50) { System.out.println("The waiter scowls at you"); } else if(tipPercent > 20 || total > 200) { System.out.println("The waiter smiles enthusiastically!"); } } }