Java Reference
In-Depth Information
Each method computes the number of dollar bills or coins to return to the
customer, and reduces the change due by the returned amount. You may
assume that the methods are called in this order. Here is a test 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");
}
}
176
177
΢΢΢Exercise P4.12. Write a program that reads in an integer and breaks it
into a sequence of individual digits in reverse order. For example, the
input 16384 is displayed as
4
8
3
6
1
You may assume that the input has no more than five digits and is not
negative.
Search WWH ::




Custom Search