-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCurrentAccount.java
More file actions
33 lines (25 loc) · 933 Bytes
/
CurrentAccount.java
File metadata and controls
33 lines (25 loc) · 933 Bytes
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
public class CurrentAccount extends Account {
private double overdraftLimit;
public CurrentAccount(int accountId, double startBalance, double overdraftLimit) {
super(accountId, startBalance);
this.overdraftLimit = overdraftLimit;
}
@Override
public double withdraw(double amount) {
if (amount <= 0)
return 0;
double available = getBalance() + overdraftLimit;
if (amount > available)
amount = available;
deposit(-amount);
return amount;
}
@Override
public String toString() {
return "\n--- Current Account ---" +
"\nAccount ID: " + getId() +
"\nBalance: $" + String.format("%.2f", getBalance()) +
"\nOverdraft Limit: $" + String.format("%.2f", overdraftLimit) +
"\nDate Created: " + getDateCreated();
}
}