-
Notifications
You must be signed in to change notification settings - Fork 0
/
polimorfismo.js
64 lines (52 loc) · 1.25 KB
/
polimorfismo.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
56
57
58
59
60
61
62
63
// Superclass
function Conta(agencia, conta, saldo) {
this.agencia = agencia;
this.conta = conta;
this.saldo = saldo;
}
Conta.prototype.sacar = function(valor) {
if(valor > this.saldo) {
console.log(`Saldo insuficiente: ${this.saldo}`);
return;
}
this.saldo -= valor;
this.verSaldo();
};
Conta.prototype.depositar = function(valor) {
this.saldo += valor;
this.verSaldo();
};
Conta.prototype.verSaldo = function() {
console.log(
`Ag/c: ${this.agencia}/${this.conta} | ` +
`Saldo: R$${this.saldo.toFixed(2)}`
);
};
function CC(agencia, conta, saldo, limite) {
Conta.call(this, agencia, conta, saldo);
this.limite = limite;
}
CC.prototype = Object.create(Conta.prototype);
CC.prototype.constructor = CC;
CC.prototype.sacar = function(valor) {
if(valor > (this.saldo + this.limite)) {
console.log(`Saldo insuficiente: ${this.saldo}`);
return;
}
this.saldo -= valor;
this.verSaldo();
};
function CP(agencia, conta, saldo) {
Conta.call(this, agencia, conta, saldo);
}
CP.prototype = Object.create(Conta.prototype);
CP.prototype.constructor = CP;
const cc = new CC(11, 22, 0, 100);
cc.depositar(10);
cc.sacar(110);
cc.sacar(1);
console.log();
const cp = new CP(12, 33, 0);
cp.depositar(10);
cp.sacar(10);
cp.sacar(1);