``````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;

}``````

## All 5 Replies

to the given types in the Tester Class. Why?

Who knows? You didn't post the tester class.

``````public class CashRegisterTester {

public static void main(String[] args)
{
CashRegister register = new CashRegister();

register.recordPurchase(8.37);
register.enterPayment(10,0,0,0,0);
System.out.println("Dollars: " + register.giveDollars());
System.out.println("Expected: 1");
System.out.println("Quarters: " + register.giveQuarters());
System.out.println("Expected: 2");
System.out.println("Dimes: " + register.giveDimes());
System.out.println("Expected: 1");
System.out.println("Nickels: " + register.giveNickels());
System.out.println("Expected: 0");
System.out.println("Pennies: " + register.givePennies());
System.out.println("Expected: 3");
}

}``````
``````public class CashRegisterTester {

public static void main(String[] args)
{
CashRegister register = new CashRegister();

register.recordPurchase(8.37);
register.enterPayment(10,0,0,0,0);
System.out.println("Dollars: " + register.giveDollars());
System.out.println("Expected: 1");
System.out.println("Quarters: " + register.giveQuarters());
System.out.println("Expected: 2");
System.out.println("Dimes: " + register.giveDimes());
System.out.println("Expected: 1");
System.out.println("Nickels: " + register.giveNickels());
System.out.println("Expected: 0");
System.out.println("Pennies: " + register.givePennies());
System.out.println("Expected: 3");
}

}``````

Who knows? You didn't post the tester class.

Method definition:

``public void giveDollars (int dollars)``

Method call:

``register.giveDollars());``

Number and types of parameters should match.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.