import javax.swing.*; public class CashierSeven { public boolean isRegularCustomer(String customerName) { if (customerName.equals("John Sanders") || customerName.equals("Rose Perez") || customerName.equals("Elizabeth Smith")) { return true; } else { return false; } } public void ringUpCustomer(String customerName) { String item; double total, change; total = costOfItems(); change = processPayment(total, customerName); printThankYouNote(customerName, change); } private double costOfItems() { String item; double total = 0.0, milkPrice = 3.50; double bottleWaterPrice = 1.0, sugarPrice = 4.0; do { item = JOptionPane.showInputDialog("Enter Item Description"); if (item.equals("milk")) { total = total + milkPrice; } else if (item.equals("bottleWater")) { total = total + bottleWaterPrice; } else if (item.equals("sugar")) { total = total + sugarPrice; } } while (!item.equals("end")); return total; } private double processPayment(double total, String customerName) { double discount = .50; if (isRegularCustomer(customerName)) { total = total * discount; } String reply = "Your total is: $" + total + "\nPlease enter payment amount."; String paymentString = JOptionPane.showInputDialog(reply); double payment = Double.parseDouble(paymentString); while (payment < total) { String wrongAmountReply = "Insufficient payment provided. \n" + reply; paymentString = JOptionPane.showInputDialog(wrongAmountReply); payment = Double.parseDouble(paymentString); } return payment - total; } private void printThankYouNote(String customerName, double change) { String reply = customerName + ", thank you for shopping with us.\n"; // Notice the use of += operator reply += ("Your change is: $" + change); JOptionPane.showMessageDialog(null, reply); } }