Giving change. Enhance the CashRegister class so that it directs a cashier how to give change. The cash register computes the amount to be returned to the customer, in pennies.
Add the following methods to the CashRegister class:
int giveDollars()
int giveQuarters()
int giveDimes()
int giveNickels()
int givePennies()
Each method computes the number of dollar bills or coins to return to the customer, and reduces the change due by the returned amount. You may assume that the methods are called in this order. Here is a test class:
public class CashRegisterTester
{
public static void main(String[] args)
{
CashRegister register = new CashRegister();
register.recordPurchase(8.37);
register.enterPayment(10, 0, 0, 0, 0);
System.out.println("Dollars: " + register.giveDollars());
System.out.println("Expected: 1");
System.out.println("Quarters: " + register.giveQuarters());
System.out.println("Expected: 2");
System.out.println("Dimes: " + register.giveDimes());
System.out.println("Expected: 1");
System.out.println("Nickels: " + register.giveNickels());
System.out.println("Expected: 0");
System.out.println("Pennies: " + register.givePennies());
System.out.println("Expected: 3");
}
}