// Allison Obourn
// CS 141, Winter 2021
// Lecture 8

// This program prompts the user for a number of people and then prompts
// them for the cost of a meal for each person. It then prints out the subtotal,
// tax, tip and total of a restaurant bill

import java.util.*;

public class Receipt {
    public static void main(String[] args) {
    
        Scanner console = new Scanner(System.in);
        System.out.print("How many people ate? ");
        int people = console.nextInt();
        
        double subtotal = 0;
        for(int i = 0; i < people; i++) {
            System.out.print("Person #" + (i + 1) + ": How much did your dinner cost? ");
            double cost = console.nextDouble();
            subtotal += cost;
        }
        
        printResults(subtotal);
    }
    
    // prints the subtotal, tax, tip and total owed, assuming 8% tax / 15% tip
    // all numbers printed out with 2 numbers after the decimal
    public static void printResults(double subtotal) {
        double tax = subtotal * .08;
        double tip = subtotal * 0.15;
        
        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", (subtotal + tip + tax));
    }
}
