Add a feature to the CashRegister class for computing sales tax. The tax rate should be supplied when constructing a CashRegister object. Add recordTaxablePurchase and getTotalTax methods. (Amounts added with recordPurchase are not taxable.)

Complete the following files:

CashRegister.java

public class CashRegister { private double purchase; private double payment; private double totalTax; private double taxRate; /** Constructs a cash register with no money in it. */ public CashRegister(double rate) { purchase=0; ... } /** Records the sale of an item. @param amount the price of the item */ public void recordPurchase(double amount) { purchase = purchase + amount; } /** Records the sale of a taxable item and compute the total tax. @param amount the price of the item */ public void recordTaxablePurchase(double amount) { ... } /** Enters the payment received from the customer. @param amount the amount of the payment */ public void enterPayment(double amount) { payment=amount; } /** Returns the total tax due @return the totalTax */ public double getTotalTax() { ... } /** Computes the change due and resets the machine for the next customer. @return the change due to the customer */ public double giveChange() { double change = ... purchase = 0; payment = 0; ... return change; } }

CashRegisterTester2.java

Use the following file:

CashRegisterTester.java

/**
   A class to test the CashRegister class.
*/
public class CashRegisterTester
{
   public static void main(String[] args)
   {
      // tax rate of 5%
      CashRegister register = new CashRegister(5);

      register.recordPurchase(29.50);
      register.recordTaxablePurchase(10.00);
      register.recordTaxablePurchase(2.00);

      System.out.println(register.getTotalTax());
      System.out.println("Expected: 0.60");

      register.enterPayment(50);

      double change = register.giveChange();

      System.out.println(change);      
      System.out.println("Expected: 7.90");          
   }
}