-
Notifications
You must be signed in to change notification settings - Fork 0
/
CoinBox.java
116 lines (96 loc) · 1.73 KB
/
CoinBox.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package vendingMachine;
/**
* @author tobyf
*
*/
public class CoinBox {
private int quarters;
private int dimes;
private int nickels;
/**
* Constructor
* Sets quarters, dimes, and nickels to 0
*/
public CoinBox() {
quarters = 0;
dimes = 0;
nickels = 0;
}
/**
* Increments quarters
*/
public void addQuarter() {
quarters++;
}
/**
* Increments dimes
*/
public void addDime() {
dimes++;
}
/**
* Increments nickels
*/
public void addNickel() {
nickels++;
}
// returns the current number of quarters
/**
* @return quarters
*/
public int getQuarters() {
return quarters;
}
// returns the current number of dimes
/**
* @return dimes
*/
public int getDimes() {
return dimes;
}
/**
* @return nickels
*/
public int getNickels() {
return nickels;
}
/**
* Decrements quarters
*/
public void removeQuarter() {
quarters -= 1;
}
/**
* Decrements dimes
*/
public void removeDime() {
dimes -= 1;
}
/**
* Decrements nickels
*/
public void removeNickel() {
nickels -= 1;
}
/**
* Sets all coins to 0
*/
public void resetCoins() {
nickels = 0;
dimes = 0;
quarters = 0;
}
// transferCoins(CoinBox)
// takes a CoinBox as input and sets this coinbox's coin values to that of
// the input CoinBox and sets the input coinbox's coin values to 0.
/**
* @param cb : coinbox to take coins from
* Transfers all coins from cb to this
*/
public void transferCoins(CoinBox cb) {
this.quarters += cb.getQuarters();
this.dimes += cb.getDimes();
this.nickels += cb.getNickels();
cb.resetCoins();
}
}