previous | start | next

Example

import java.util.Scanner;

/**
 * A class to test the CashRegister class.
 */
public class CashRegisterTester {
  public static void main(String[] args) {
    CashRegister register = new CashRegister();
    Scanner in = new Scanner(System.in);

    System.out.println("Price for first item:");
    double price1 = in.nextDouble();

    System.out.println("Price for second item:");
    double price2 = in.nextDouble();

    System.out.println("Payment amount:");
    double payment = in.nextDouble();

    register.recordPurchase(price1);
    register.recordPurchase(price2);
    register.enterPayment(payment);

    double change = register.giveChange();

    System.out.printf("Your change is %.2f. Have a nice day!\n",
                      change);
            
    System.exit(0);
  }
}


previous | start | next