Question: After closing time the store manager would like to know how much business was transacted during the day. Modify the CashRegister class to enable this
After closing time the store manager would like to know how much business was transacted during the day. Modify the CashRegister class to enable this functionality. Supply methods getSalesTotal and getSalesCount to get the total amount of all sales and the number of sales. Supply a method resetSales that resets any counters and totals so that the next day's sales start from zero.
Here is my current CashRegister class,
import java.util.ArrayList;
/**
A simulated cash register that tracks the item count and
the total amount due.
*/
public class CashRegister
{
private ArrayList
private ArrayList
private double taxRate;
/**
Constructs a cash register with cleared item count and total.
@param aTaxRate the tax rate to use with this cash register.
*/
public CashRegister(double aTaxRate)
{
prices = new ArrayList<>();
taxables = new ArrayList<>();
taxRate = aTaxRate;
}
/**
Adds an item to this cash register.
@param price the price of this item
@param taxable true if this item is taxable
*/
public void addItem(double price, boolean taxable)
{
prices.add(price);
taxables.add(taxable);
}
/**
Gets the price of all items in the current sale.
@return the total amount
*/
public double getTotal()
{
double totalPrice = 0;
double taxableTotal = 0;
for(int i = 0; i < prices.size(); ++i) {
totalPrice += prices.get(i);
if(taxables.get(i)) {
taxableTotal += prices.get(i);
}
}
return totalPrice + taxableTotal * taxRate / 100;
}
/**
Gets the number of items in the current sale.
@return the item count
*/
public int getCount()
{
return prices.size();
}
/**
Clears the item count and the total.
*/
public void clear()
{
prices.clear();
taxables.clear();
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
