// Yazzy Latif // 06/26/2020 // TA: Grace Hopper // Coffee Order Example // This program calculates the bill for a coffee run made for some of your TAs. // It includes a 9.5% tax, and a 5% "preferred customer" discount. /* DEVELOPMENT NOTES: ((Note: this is not something you should include in your own programs; this is included here to aid in your understanding and to provide additional context for the program.)) Note that we use variables to capture repeated expressions (reducing redundancy) as well as improving readability by creating variables for the prices of different drinks, even though they are only used once! */ public class CoffeeOrder { public static void main(String[] args) { // late ($5.50), frappuccino ($6.25), drip ($2.00) // Ana: latte, Aidan: frap, Nancy: latte, Sumant: drip double lattePrice = 5.50; double frapPrice = 6.25; double dripPrice = 2.00; int numLatte = 2; double subtotal = numLatte * lattePrice + frapPrice + dripPrice; double tax = 0.095 * subtotal; double discount = 0.05 * subtotal; double total = subtotal - discount + tax; System.out.println("Subtotal: $" + subtotal); System.out.println("Tax: $" + tax); System.out.println("Discount: ($" + discount + ")"); System.out.println("TOTAL: $" + total); // Extra example showcasing integer division // 4 coffee drinkers // 12 tas int numCoffeeDrinkers = 4; int numTAs = 12; // Bug in the following line, makes the coffeePercentage // 0.0 because of integer division, we need to cast // to a double or swap the order of the expression // double coffeePercenttage = (numCoffeeDrinkers / numTAs * 100); double coffeePercentage = 100.0 * numCoffeeDrinkers / numTAs; System.out.println("coffee percentage = " + coffeePercentage); } }