hello everyone,
new person here. i'm a college student working on my programming homework. i have a class CashRegister that reads the payment in and calculates change due. i have to add a new method to it called getItemCount() that keeps track of the total number of items in a sale. it returns the number of items in the current purchase. remember to reset the count at the end of the purchase. how do i do this?
public class CashRegister
{
/**
* Constructs a cash register with no money in it
* */
public CashRegister()
{
purchase = 0;
payment = 0;
}
public int getItemCount()
{
/**
* Records the purchase price of an item.
* @param amount the price of a purchased item
* */
public void recordPurchase(double amount)
{
purchase = purchase + amount;
}
/**
* Enters the amount in bills received from the customer
* */
public void enterDollars(int dollars)
{
payment = dollars;
}
/*
* the following methods take the number of each coins given, and multiply them by
* their constant value and add that to the total payment received
* */
public void enterQuarters(int quarters)
{
payment = payment + quarters * QUARTER_VALUE;
}
public void enterDimes(int dimes)
{
payment = payment + dimes * DIME_VALUE;
}
public void enterNickels(int nickels)
{
payment = payment + nickels * NICKEL_VALUE;
}
public void enterPennies(int pennies)
{
payment = payment + pennies * PENNY_VALUE;
}
/*
* this method supplies the total payment received and subtracts the purchase price.
* change is then computed.
* */
public double giveChange()
{
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
public static final double QUARTER_VALUE = .25;
public static final double DIME_VALUE = .1;
public static final double NICKEL_VALUE = .05;
public static final double PENNY_VALUE = .01;
private double purchase;
private double payment;
}