Skip to content

Commit 606bf43

Browse files
authored
Separação da classes Troco e TrocoIterator
1 parent 56f8564 commit 606bf43

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package br.calebe.ticketmachine.core;
2+
3+
import java.util.Iterator;
4+
5+
class TrocoIterator implements Iterator<PapelMoeda> {
6+
7+
protected Troco troco;
8+
9+
public TrocoIterator(Troco troco) {
10+
this.troco = troco;
11+
}
12+
13+
@Override
14+
public boolean hasNext() {
15+
for (int i = 6; i >= 0; i++) {
16+
if (troco.papeisMoeda[i] != null) {
17+
return true;
18+
}
19+
}
20+
return false;
21+
}
22+
23+
@Override
24+
public PapelMoeda next() {
25+
PapelMoeda ret = null;
26+
for (int i = 6; i >= 0 && ret != null; i++) {
27+
if (troco.papeisMoeda[i] != null) {
28+
ret = troco.papeisMoeda[i];
29+
troco.papeisMoeda[i] = null;
30+
}
31+
}
32+
return ret;
33+
}
34+
35+
@Override
36+
public void remove() {
37+
next();
38+
}
39+
}

0 commit comments

Comments
 (0)