forked from alura-cursos/js-heranca-polimorfismo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContaCorrente.js
55 lines (40 loc) · 977 Bytes
/
ContaCorrente.js
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
import {
Cliente
} from "./Cliente.js";
export class ContaCorrente {
static numeroDeContas = 0;
// #saldo =0 https://github.com/tc39/proposal-class-fields#private-fields
set cliente(novoValor) {
if (novoValor instanceof Cliente) {
this._cliente = novoValor;
}
}
get cliente() {
return this._cliente;
}
get saldo() {
return this._saldo;
}
constructor(agencia, cliente) {
this.agencia = agencia;
this.cliente = cliente;
this._saldo = 0;
ContaCorrente.numeroDeContas += 1;
}
sacar(valor) {
if (this._saldo >= valor) {
this._saldo -= valor;
return valor;
}
}
depositar(valor) {
if (valor <= 100) {
return;
}
this._saldo += valor;
}
tranferir(valor, conta) {
const valorSacado = this.sacar(valor);
conta.depositar(valorSacado);
}
}