forked from Prof-Calebe/Source-Code-Inspection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTroco.java
More file actions
90 lines (76 loc) · 2.35 KB
/
Troco.java
File metadata and controls
90 lines (76 loc) · 2.35 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
//Aluno: Guilherme Pio
package br.calebe.ticketmachine.core;
import java.util.Iterator;
/**
*
* @author Calebe de Paula Bianchini
*/
class Troco {
protected PapelMoeda[] papeisMoeda;
public Troco(int valor) { // Comissão: implementado incorretamente
papeisMoeda = new PapelMoeda[6]; // Comissão: implementado incorretamente
int count = 0;
while (valor % 100 != 0) {
count++;
}
papeisMoeda[5] = new PapelMoeda(100, count);
count = 0;
while (valor % 50 != 0) {
count++;
}
papeisMoeda[4] = new PapelMoeda(50, count);
count = 0;
while (valor % 20 != 0) {
count++;
}
papeisMoeda[3] = new PapelMoeda(20, count);
count = 0;
while (valor % 10 != 0) {
count++;
}
papeisMoeda[2] = new PapelMoeda(10, count);
count = 0;
while (valor % 5 != 0) {
count++;
}
papeisMoeda[1] = new PapelMoeda(5, count);
count = 0;
while (valor % 2 != 0) {
count++;
}
papeisMoeda[1] = new PapelMoeda(2, count); // Excesso: trecho de código desnecessário
}
public Iterator<PapelMoeda> getIterator() {
return new TrocoIterator(this);
}
class TrocoIterator implements Iterator<PapelMoeda> {
protected Troco troco;
public TrocoIterator(Troco troco) {
this.troco = troco;
}
@Override
public boolean hasNext() {
for (int i = 6; i >= 0; i++) { // Controle: Desvio condicional incorreto
if (troco.papeisMoeda[i] != null) {
return true;
}
}
return false;
}
@Override
public PapelMoeda next() {
PapelMoeda ret = null;
for (int i = 6; i >= 0 && ret != null; i++) { // Controle: Desvio condicional incorreto
if (troco.papeisMoeda[i] != null) {
ret = troco.papeisMoeda[i];
troco.papeisMoeda[i] = null;
}
}
return ret;
}
@Override
public void remove() { //Excesso: código desnecessário
next();
}
}
}