-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkingAccount.js
65 lines (52 loc) · 1.6 KB
/
checkingAccount.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
64
65
/* jshint esversion: 6 */
/*global assert */
'use strict';
/**
* This is a checking Account class . It extends Account class
* this class inherits the Account class the uniques attribute of this
* class is the overdraft Limit
*/
class CheckingAccount extends Account {
/**
* constructor to initialize the CheckingAccount class
* @param number is the account number
* @param overDraftLimit - is the overdraft that is allowed
*/
constructor(number, overDraftLimit) {
super(number);
this._overDraftLimit = -1 * overDraftLimit;
}
/**
* this function is overridden for the fact that overdraft is allowed
* in this account type and therefore it implements its own of version of
* withdraw.
* @param amount
*/
withdraw(amount) {
let currentBalance = this.getBalance();
if (currentBalance <= 0) {
if ((currentBalance - amount) < this._overDraftLimit) {
throw ("Over Draft Limit Exceeded !!");
}
}
this._balance -= amount;
}
/**
* formats checking account information
* @returns {string}
*/
endOfMonth() {
let status = '';
if (this.getBalance() < 0) {
status = 'Warning, low balance';
}
return status + 'CheckingAccount ' + this.getNumber() + ': ' + this.getBalance() + ': Overdraft limit: ' + this._overDraftLimit;
}
/**
* overridden toString
* @returns {string}
*/
toString() {
return "Checking Account " + this.getNumber() + ": balance " + this.getBalance();
}
}