-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHomeWork_10_2.js
More file actions
103 lines (79 loc) · 2.43 KB
/
HomeWork_10_2.js
File metadata and controls
103 lines (79 loc) · 2.43 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
class Account {
get id() {
return this._id;
}
get name() {
return this._name;
}
set name(value) {
this._name = value;
}
get balance() {
return this._balance;
}
set balance(value) {
if (typeof value === "number") {
this._balance = value;
}
}
credit(amount) {
if (typeof amount === "number") {
return this._balance = this.balance + amount;
}
}
debit(amount) {
if (typeof amount === "number") {
if (amount > this.balance) {
return "Amount exceeds the balance";
}
return this._balance = this.balance - amount;
}
}
transferTo(anotherAccount, amount) {
if (anotherAccount instanceof Account && typeof amount === "number") {
if (amount > this.balance) {
return "Amount exceeds the balance";
}
anotherAccount._balance += amount;
return this._balance = this.balance - amount;
}
}
static identifyAccounts(accountFirst, accountSecond) {
if (accountFirst instanceof Account && accountSecond instanceof Account) {
for (let key in accountFirst) {
if (accountFirst[key] !== accountSecond[key]) {
console.log("This accounts are not the same");
return false;
}
}
console.log("The accounts are identical");
return true;
}
console.log("Please enter correct instances");
return false;
}
constructor(id, name, balance) {
this._id = id;
this.name = name;
this.balance = balance;
}
}
let accountOne = new Account("1234", "", 0);
accountOne.name = "First Account";
accountOne.balance = 10000;
console.log(accountOne.credit(9000));
console.log(accountOne.debit(2000));
console.log("************************");
console.log(accountOne.name);
console.log(accountOne.balance);
console.log(accountOne.id);
console.log("************************");
let accountTwo = new Account("1234", "Second Account",15000);
console.log(accountTwo.name);
console.log(accountTwo.balance);
console.log(accountTwo.id);
console.log("************************");
Account.identifyAccounts(accountOne, accountTwo);
accountOne.transferTo(accountTwo, 5000);
console.log(accountOne.balance);
console.log(accountTwo.balance);