-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConta.java
More file actions
61 lines (49 loc) · 1.5 KB
/
Conta.java
File metadata and controls
61 lines (49 loc) · 1.5 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
abstract class Conta implements InterfaceConta{
public static final int AGENCIA_PADRAO = 1;
private static int SEQUENTIAL = 1;
protected int agencia;
protected int numero;
protected double saldo;
protected Cliente cliente;
public Conta(Cliente cliente) {
this.agencia = AGENCIA_PADRAO;
this.numero = SEQUENTIAL++;
this.cliente = cliente;
}
@Override
public void sacar(double valorSaque){
if(valorSaque > this.saldo){
System.err.println("Saldo insuficiente!");
} else {
this.saldo -= valorSaque;
}
}
@Override
public void depositar(double valor){
if(valor < 0) {
System.err.println("O valor de deposito precisa ser maior que 0!");
} else{
this.saldo += valor;
}
}
@Override
public void transferir(double valor, Conta contaDestino){
this.sacar(valor);
contaDestino.depositar(valor);
}
public int getAgencia() {
return agencia;
}
public int getNumero() {
return numero;
}
public double getSaldo() {
return saldo;
}
protected void imprimirInfosComuns() {
System.out.println(String.format("Titular: %s", this.cliente.getNome()));
System.out.println(String.format("Agencia: %d", this.getAgencia()));
System.out.println(String.format("Numero: %d", this.getNumero()));
System.out.println(String.format("Saldo: %.2f", this.getSaldo()));
}
}