1 /**
2 */
3 public class StampMachine
4 {
5 public static final int FIRST_CLASS_STAMP_PRICE = 44;
6 private int balance;
7
8 /**
9 Constructs a stamp machine with a zero balance.
10 */
11 public StampMachine()
12 {
13 balance = 0;
14 }
15
16 /**
17 Adds a given number of dollar bills into this machine.
18 @param dollars the number of dollar bills
19 */
20 public void insert(int dollars)
21 {
22 balance = balance + 100 * dollars;
23 }
24
25 /**
26 Dispenses first class stamps for the inserted payment.
27 @return the number of first class stamps
28 */
29 public int giveFirstClassStamps()
30 {
31 int firstClassStamps = balance / FIRST_CLASS_STAMP_PRICE;
32 balance = balance - firstClassStamps * FIRST_CLASS_STAMP_PRICE;
33 return firstClassStamps;
34 }
35
36 /**
37 Dispenses penny stamps for the inserted payment.
38 @return the number of penny stamps
39 */
40 public int givePennyStamps()
41 {
42 int pennyStamps = balance;
43 balance = 0;
44 return pennyStamps;
45 }
46 }