forked from Prof-Calebe/Source-Code-Inspection
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTicketMachine.java
More file actions
56 lines (45 loc) · 1.59 KB
/
TicketMachine.java
File metadata and controls
56 lines (45 loc) · 1.59 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
//Aluno: Guilherme Pio
package br.calebe.ticketmachine.core;
import br.calebe.ticketmachine.exception.PapelMoedaInvalidaException;
import br.calebe.ticketmachine.exception.SaldoInsuficienteException;
import java.util.Iterator;
/**
*
* @author Calebe de Paula Bianchini
*/
public class TicketMachine {
protected int valor; // Comissão: Atributos não condizem com o diagrama de classes
protected int saldo;
protected int[] papelMoeda = {2, 5, 10, 20, 50, 100};
public TicketMachine(int valor) { // Comissão: Entrada não condiz com o diagrama de classes
this.valor = valor;
this.saldo = 0;
}
public void inserir(int quantia) throws PapelMoedaInvalidaException {
boolean achou = false;
for (int i = 0; i < papelMoeda.length && !achou; i++) {
if (papelMoeda[1] == quantia) { // Dados: Acessa somente um índice
achou = true;
}
}
if (!achou) {
throw new PapelMoedaInvalidaException();
}
this.saldo += quantia;
}
public int getSaldo() {
return saldo;
}
public Iterator<Integer> getTroco() {
return null; // Computação: Somente um retorno para o troco.
}
public String imprimir() throws SaldoInsuficienteException {
if (saldo < valor) {
throw new SaldoInsuficienteException();
}
String result = "*****************\n";
result += "*** R$ " + saldo + ",00 ****\n";
result += "*****************\n";
return result;
}
}