forked from mulangonando/Advanced-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ2.java
More file actions
52 lines (43 loc) · 1.51 KB
/
Copy pathQ2.java
File metadata and controls
52 lines (43 loc) · 1.51 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
class DepositTransaction extends BaseTransaction {
public DepositTransaction(double amount) {
super(amount);
}
@Override
public void printTransactionDetails() {
System.out.println("Deposit Transaction");
super.printTransactionDetails();
}
@Override
public void apply(BankAccount ba) {
ba.deposit(this.amount);
System.out.println("Deposit of $" + this.amount + " applied. New Balance: $" + ba.getBalance());
}
}
class WithdrawalTransaction extends BaseTransaction {
private BankAccount account;
private boolean reversed;
public WithdrawalTransaction(double amount) {
super(amount);
this.reversed = false;
}
@Override
public void printTransactionDetails() {
System.out.println("Withdrawal Transaction");
super.printTransactionDetails();
}
@Override
public void apply(BankAccount ba) throws InsufficientFundsException {
ba.withdraw(this.amount);
this.account = ba;
System.out.println("Withdrawal of $" + this.amount + " applied. New Balance: $" + ba.getBalance());
}
public boolean reverse() {
if (this.account != null && !this.reversed) {
this.account.deposit(this.amount);
this.reversed = true;
System.out.println("Withdrawal reversed. Balance restored to: $" + this.account.getBalance());
return true;
}
return false;
}
}