forked from mulangonando/Advanced-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.java
More file actions
39 lines (32 loc) · 1.33 KB
/
Copy pathQ4.java
File metadata and controls
39 lines (32 loc) · 1.33 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
public class Main {
public static void main(String[] args) {
BankAccount account = new BankAccount("123456789", 1000.00);
DepositTransaction deposit = new DepositTransaction(500.00);
deposit.printTransactionDetails();
deposit.apply(account);
WithdrawalTransaction withdrawal = new WithdrawalTransaction(200.00);
withdrawal.printTransactionDetails();
try {
withdrawal.apply(account);
} catch (InsufficientFundsException e) {
System.out.println(e.getMessage());
}
withdrawal.reverse();
WithdrawalTransaction partialWithdrawal = new WithdrawalTransaction(2000.00);
partialWithdrawal.apply(account, true);
BaseTransaction baseTx1 = (BaseTransaction) deposit;
baseTx1.printTransactionDetails();
try {
baseTx1.apply(account);
} catch (InsufficientFundsException e) {
System.out.println(e.getMessage());
}
BaseTransaction baseTx2 = (BaseTransaction) withdrawal;
baseTx2.printTransactionDetails();
try {
baseTx2.apply(account);
} catch (InsufficientFundsException e) {
System.out.println(e.getMessage());
}
}
}