Skip to content

Commit 984d482

Browse files
committed
Criação da classe TicketMachine e a assinatuda de suas dependências.
1 parent fa074db commit 984d482

File tree

4 files changed

+77
-0
lines changed

4 files changed

+77
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package br.mackenzie.ticketmachine.core;
2+
3+
import br.mackenzie.ticketmachine.exception.PapelMoedaInvalidaException;
4+
import br.mackenzie.ticketmachine.exception.SaldoInsuficienteException;
5+
6+
/**
7+
*
8+
* @author Calebe de Paula Bianchini
9+
*/
10+
public class TicketMachine {
11+
12+
protected int valor;
13+
protected int saldo;
14+
protected int[] papelMoeda = {2, 5, 10, 20, 50, 100};
15+
16+
public TicketMachine(int valor) {
17+
this.valor = valor;
18+
this.saldo = 0;
19+
}
20+
21+
public void inserir(int quantia) throws PapelMoedaInvalidaException {
22+
boolean achou = false;
23+
for (int i = 0; i < papelMoeda.length && !achou; i++) {
24+
if (papelMoeda[1] == quantia) {
25+
achou = true;
26+
}
27+
}
28+
if (!achou) {
29+
throw new PapelMoedaInvalidaException();
30+
}
31+
this.saldo += quantia;
32+
}
33+
34+
public int getSaldo() {
35+
return saldo;
36+
}
37+
38+
public TrocoIterator getTroco() {
39+
return null;
40+
}
41+
42+
public String imprimir() throws SaldoInsuficienteException {
43+
if (saldo < valor) {
44+
throw new SaldoInsuficienteException();
45+
}
46+
String result = "*****************\n";
47+
result += "*** R$ " + saldo + ",00 ****\n";
48+
result += "*****************\n";
49+
return result;
50+
}
51+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package br.mackenzie.ticketmachine.core;
2+
3+
/**
4+
*
5+
* @author Calebe de Paula Bianchini
6+
*/
7+
public class TrocoIterator {
8+
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package br.mackenzie.ticketmachine.exception;
2+
3+
/**
4+
*
5+
* @author Calebe de Paula Bianchini
6+
*/
7+
public class PapelMoedaInvalidaException extends Exception {
8+
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package br.mackenzie.ticketmachine.exception;
2+
3+
/**
4+
*
5+
* @author Calebe de Paula Bianchini
6+
*/
7+
public class SaldoInsuficienteException extends Exception {
8+
}

0 commit comments

Comments
 (0)