Lab 6

Cash Register

In this assignment, you'll extend the shopping list example we created in class by building a cash register application.

Your application will ask the ask the user to enter items into an register, and will output a sales receipt at the end of the process. You should ask the user to enter data into the register until they are finished rather than artificially restricting the number of items they can enter.

RetailItem Class

Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields:

      • description. The description field references a String object that holds a brief description of the item.
      • unitsOnHand. The unitsOnHand field is an int variable that holds the number of units currently in inventory.
      • price. The price field is a double that holds the item’s retail price.
      1. Write a constructor that accepts arguments for each field, appropriate mutator methods that store values in these fields, and accessor methods that return the values in these fields.

CashRegister Class

Write a CashRegister class that can be used with the RetailItem class. The CashRegister class should simulate the sale of a retail item. In addition, the class should have the following methods:

      • addItem which accepts an argument of a RetailItem and adds that item to the current sale.
      • The getSubtotal method should return the subtotal of the sale, which is the quantity multiplied by the price. This method must get the price from the RetailItem object that was passed as an argument to the constructor.
      • The getTax method should return the amount of sales tax on the purchase. The sales tax rate is 6 percent of a retail sale.
      • The getTotal method should return the total of the sale, which is the subtotal plus the sales tax.

Sales Receipt

  1. Output a sales receipt showing the output of all of the items entered into the cash register.
Sales Receipt:
Items: 3
Subtotal: $15.00
Sales-Tax: $5.00
Total: $20.00