-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVault.java
More file actions
95 lines (79 loc) · 2.18 KB
/
Copy pathVault.java
File metadata and controls
95 lines (79 loc) · 2.18 KB
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
// The vault, where the money is stored and accessed
import java.util.ArrayList;
import java.util.Iterator;
import java.util.ListIterator;
public class Vault {
private final ArrayList<Bill> fives = new ArrayList<>();
private final ArrayList<Bill> tens = new ArrayList<>();
private final ArrayList<Bill> twenties = new ArrayList<>();
private final ArrayList<Bill> fifties = new ArrayList<>();
private ListIterator<Bill> getFifties(int amt) {
if (fifties.size() * 50 >= amt) {
return fifties.listIterator(fifties.size() - amt);
}
return null;
}
private ListIterator<Bill> getFives(int amt) {
if (fives.size() * 5 >= amt) {
return fives.listIterator(fives.size() - amt);
}
return null;
}
public int getNumOfFifties() {
return fifties.size();
}
public int getNumOfFives() {
return fives.size();
}
public int getNumOfTens() {
return tens.size();
}
public int getNumOfTwenties() {
return twenties.size();
}
private ListIterator<Bill> getTens(int amt) {
if (tens.size() * 10 >= amt) {
return tens.listIterator(tens.size() - amt);
}
return null;
}
/**
* Gets the total dollar value of all of the bills in the vault
*
* @return The dollar value of the entire contents of the vault
*/
public int getTotal() {
return (fives.size() * 5 + tens.size() * 10 + twenties.size() * 20 + fifties.size() * 50);
}
private ListIterator<Bill> getTwenties(int amt) {
if (twenties.size() * 20 >= amt) {
return twenties.listIterator(twenties.size() - amt);
}
return null;
}
public void addFifties(ArrayList<Bill> fifties) {
this.fifties.addAll(fifties);
}
public void addFives(ArrayList<Bill> fives) {
this.fives.addAll(fives);
}
public void addTens(ArrayList<Bill> tens) {
this.tens.addAll(tens);
}
public void addTwenties(ArrayList<Bill> twenties) {
this.twenties.addAll(twenties);
}
public Iterator<Bill> getDenominationValue(int i) {
switch (i) {
case 5:
return getFives(i);
case 10:
return getTens(i);
case 20:
return getTwenties(i);
case 50:
return getFifties(i);
}
return null;
}
}