-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path8-1-Account.js
57 lines (50 loc) Β· 1 KB
/
8-1-Account.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
/**
* p285 μμ
*/
class Account {
#type;
#daysOverdrawn;
constructor(type, daysOverdrawn) {
this.#type = type;
this.#daysOverdrawn = daysOverdrawn;
}
get type() {
return this.#type;
}
get daysOverdrawn() {
return this.#daysOverdrawn;
}
get bankCharge() {
let result = 4.5;
if (this.#daysOverdrawn > 0) {
result += this.type.overdraftCharge(this);
}
return result;
}
}
class AccountType {
#type;
constructor(type) {
this.#type = type;
}
get isPremium() {
return this.#type === 'Premium';
}
overdraftCharge(account) {
if (this.isPremium) {
const baseCharge = 10;
if (account.daysOverdrawn <= 7) {
return baseCharge;
} else {
return baseCharge + (account.daysOverdrawn - 7) * 0.85;
}
} else {
return account.daysOverdrawn * 1.75;
}
}
}
/**
* μμ μ€νμ μν μμμ μ½λ
*/
const account = new Account(new AccountType('Premium'), 8);
console.log(account.bankCharge);