import java.io.*; import java.util.*; // This program reads in a file that has a list of all items order for a // meal at a restaurant. This program reads each line in the file and // calculates the subtotal, tax, tip, and total. public class Meals { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("meals.txt")); int tableCounter = 0; while (input.hasNextLine()) { tableCounter++; String meal = input.nextLine(); Scanner line = new Scanner(meal); double subtotal = 0.0; while (line.hasNextDouble()) { subtotal += line.nextDouble(); } System.out.print("Table " + tableCounter + ": "); printReceipt(subtotal); } } public static void printReceipt(double subtotal) { double tax = subtotal * .08; double tip = subtotal * .15; System.out.printf("Subtotal: $%.2f; ", subtotal); System.out.printf("Tax: $%.2f; ", tax); System.out.printf("Tip: $%.2f; ", tip); System.out.printf("Total: $%.2f\n", subtotal + tax + tip); } }