-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckingAccount.java
More file actions
49 lines (40 loc) · 1.48 KB
/
CheckingAccount.java
File metadata and controls
49 lines (40 loc) · 1.48 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
public class CheckingAccount extends BankAccount {
private MonetaryValue overdraftLimit;
public CheckingAccount() {
super();
overdraftLimit = new MonetaryValue();
}
public CheckingAccount(int accountNumber, Name name, MonetaryValue balance, MonetaryValue overdraftLimit) {
super(accountNumber, name, balance);
this.overdraftLimit = overdraftLimit;
}
public CheckingAccount(CheckingAccount copyOf) {
super(copyOf);
this.overdraftLimit = copyOf.overdraftLimit;
}
@Override
public boolean equals(Object obj) {
if (obj instanceof CheckingAccount) {
CheckingAccount other = (CheckingAccount) obj;
return super.equals(other) && this.overdraftLimit.equals(other.overdraftLimit);
}
return false;
}
@Override
public String toString() {
return "Checking Account:\n" + super.toString() + "\n" + "Overdraft Limit:" + overdraftLimit;
}
@Override
public MonetaryValue availableAmount() {
MonetaryValue totalAmount = new MonetaryValue(getBalance().doubleValue() + overdraftLimit.doubleValue());
return totalAmount;
}
public static CheckingAccount read(java.util.Scanner sc) {
if (sc.hasNext()) {
CheckingAccount newAccount = new CheckingAccount(sc.nextInt(), Name.read(sc), MonetaryValue.read(sc),
MonetaryValue.read(sc));
return newAccount;
}
return null;
}
}