Java Reference
In-Depth Information
35 payment = dollars + quarters *
QUARTER_VALUE + dimes * DIME_VALUE
36 + nickels *
NICKEL_VALUE + pennies * PENNY_VALUE;
37 }
38
39 /**
40
Computes the change due and resets the machine for the
next customer.
41 @return
the change due to the customer
42 *
43
public double
giveChange()
44 {
45
double
change = payment - purchase;
46 purchase =
0
;
47 payment =
0
;
48
return
change;
49 }
50
51
public static final double
QUARTER_VALUE
=
0.25
;
52
public static final double
DIME_VALUE =
0.1
;
53
public static final double
NICKEL_VALUE
=
0.05
;
54
public static final double
PENNY_VALUE =
0.01
;
55
56
private double
purchase;
57
private double
payment;
58 }
143
144
ch04/cashregister/CashRegisterTester.java
1 /**
2
This class tests the CashRegister class.
3 */
4
public class
CashRegisterTester
5 {
6
public static void
main(String[] args)
7 {
8 CashRegister register =
new
CashRegister();
9