Banking System
unknown
plain_text
2 years ago
1.2 kB
16
Indexable
function main() {
class Account {
#accountNumber;
#balance;
constructor(accountNumber) {
this.#accountNumber = accountNumber;
this.#balance = 0;
}
get balance() {
return this.#balance;
}
set balance(value) {
if (value < 0) {
console.log("Please enter a positive value for the balance.");
} else {
this.#balance = value;
}
}
deposit(amount) {
if (amount > 0) {
this.#balance += amount;
} else {
console.log("Please enter a positive amount to deposit.");
}
}
withdraw(amount) {
if (amount <= this.#balance) {
this.#balance -= amount;
} else {
console.log("Insufficient balance.");
}
}
get getbalance() {
return this.balance;
}
}
const myAccount = new Account("1234567890");
myAccount.deposit(500);
myAccount.withdraw(200);
console.log(myAccount.getbalance); // should output: 300
return Account;
}
main();
Editor is loading...
Leave a Comment