public class CashRegister {
public CashRegister()
{
purchase = 0;
payment = 0;
}
public void recordPuchase(double amount)
{
purchase = purchase + amount;
}
public void enterPayment(int dollars, int quarters, int dimes, int nickels, int pennies)
{
payment = dollars + quarters* QUARTER_VALUE + dimes*DIME_VALUE + nickels*NICKEL_VALUE + pennies*PENNY_VALUE;
}
public void enterDollars (int dollars)
{
payment = payment + dollars;
}
public void giveDollars (int dollars)
{
payment = payment + dollars;
}
public void enterQuarters(int quarters)
{
payment = payment + quarters*QUARTER_VALUE;
}
public void giveQuarters(int quarters)
{
payment = payment + quarters*QUARTER_VALUE;
}
public void enterDimes (int dimes)
{
payment= payment + dimes*DIME_VALUE;
}
public void giveDimes (int dimes)
{
payment= payment + dimes*DIME_VALUE;
}
public void enterNickels (int nickels)
{
payment= payment + nickels*NICKEL_VALUE;
}
public void giveNickels (int nickels)
{
payment= payment + nickels*NICKEL_VALUE;
}
public void enterPennies (int pennies)
{
payment= payment + pennies*PENNY_VALUE;
}
public void givePennies (int pennies)
{
payment= payment + pennies*PENNY_VALUE;
}
public double giveChange()
{
double change = payment - purchase;
purchase = 0;
payment = 0;
return change;
}
public static final double QUARTER_VALUE = 0.25;
public static final double DIME_VALUE = 0.1;
public static final double NICKEL_VALUE = 0.05;
public static final double PENNY_VALUE = 0.01;
public double purchase;
public double payment;
}
TigerTeck 0 Light Poster
TigerTeck 0 Light Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
TigerTeck 0 Light Poster
TigerTeck 0 Light Poster
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.