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.
Write a class named
RetailItem that holds data about an item in a retail store. The class should have the following fields:
descriptionfield references a
Stringobject that holds a brief description of the item.
unitsOnHandfield is an
intvariable that holds the number of units currently in inventory.
pricefield is a
doublethat holds the item’s retail price.
- 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 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:
addItemwhich accepts an argument of a
RetailItemand adds that item to the current sale.
getSubtotalmethod should return the subtotal of the sale, which is the quantity multiplied by the price. This method must get the price from the
RetailItemobject that was passed as an argument to the constructor.
getTaxmethod should return the amount of sales tax on the purchase. The sales tax rate is 6 percent of a retail sale.
getTotalmethod should return the total of the sale, which is the subtotal plus the sales tax.
- Output a sales receipt showing the output of all of the items entered into the cash register.