-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
156 lines (115 loc) · 5.15 KB
/
Test.java
File metadata and controls
156 lines (115 loc) · 5.15 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package polymorphism;
public class Test {
public static void main(String[] args) {
BankBranch branch = new BankBranch("Clementi Central");
branch.addAccount(new SavingsAccount("S111-1111-111", "S1111111A", 2000.0));
branch.addAccount(new CurrentAccount("C222-2222-222", "S3333333B", 2000.0));
branch.addAccount(new OverdraftAccount("O333-3333-333", "S2222222B", 2000.0));
branch.addAccount(new OverdraftAccount("O444-4444-444", "S2222222B", -2000.0));
System.out.println(branch);
System.out.println("\n---- Print all accounts ----");
branch.printAccounts();
System.out.println("\n---- Deposits and interest ----");
System.out.println("Total deposits: " + branch.totalDeposits());
System.out.println("Total interest paid to accounts: " + branch.totalInterestPaid());
System.out.println("Total negative deposits: " + branch.totalNegativeDeposits());
System.out.println("Total interest earned from accounts: " + branch.totalInterestEarned());
System.out.println("\n---- Print all unique customer IDs ----");
branch.printCustomers();
//testSavingsAccounts();
//testCurrentAccounts();
//testOverdraftAccounts();
}
public static void testSavingsAccounts() {
System.out.println("----------- Test Savings Accounts ----------");
boolean isSuccessful;
SavingsAccount savingsAccount = new SavingsAccount("S111-1111-111", "S1111111A", 2000.0);
System.out.println(savingsAccount);
System.out.println("\n--- Calculating and crediting interest ---");
System.out.println("Interest: " + savingsAccount.calculateInterest());
System.out.println("Interest is credited");
savingsAccount.creditInterest();
System.out.println(savingsAccount);
System.out.println("\n--- Withdrawing --- ");
isSuccessful = savingsAccount.withdraw(500.0);
if (isSuccessful) {
System.out.println("500.00 is withdrawn");
} else {
System.out.println("500.00 cannot be withdrawn because balance is not enough");
}
System.out.println(savingsAccount);
System.out.println(); // New line
isSuccessful = savingsAccount.withdraw(2000.0);
if (isSuccessful) {
System.out.println("2000.0 is withdrawn");
} else {
System.out.println("2000.0 cannot be withdrawn because balance is not enough");
}
System.out.println(savingsAccount);
System.out.println(); // New line
}
static void testCurrentAccounts() {
System.out.println("----------- Test Current Accounts ----------");
boolean isSuccessful;
CurrentAccount currentAccount = new CurrentAccount("C222-2222-222", "S3333333B", 2000.0);
System.out.println(currentAccount);
System.out.println("\n--- Calculating and crediting interest ---");
System.out.println("Interest: " + currentAccount.calculateInterest());
System.out.println("Interest is credited");
currentAccount.creditInterest();
System.out.println(currentAccount);
System.out.println("\n--- Withdrawing --- ");
isSuccessful = currentAccount.withdraw(500.0);
if (isSuccessful) {
System.out.println("500.00 is withdrawn");
} else {
System.out.println("500.00 cannot be withdrawn because balance is not enough");
}
System.out.println(currentAccount);
System.out.println(); // New line
isSuccessful = currentAccount.withdraw(2000.0);
if (isSuccessful) {
System.out.println("2000.0 is withdrawn");
} else {
System.out.println("2000.0 cannot be withdrawn because balance is not enough");
}
System.out.println(currentAccount);
System.out.println(); // New line
}
public static void testOverdraftAccounts() {
System.out.println("----------- Test Overdraft Accounts ----------");
boolean isSuccessful;
OverdraftAccount overdraftAccount1 = new OverdraftAccount("O333-3333-333", "S2222222B", 2000);
System.out.println(overdraftAccount1);
System.out.println("\n--- Calculating and crediting interest ---");
System.out.println("Interest: " + overdraftAccount1.calculateInterest());
System.out.println("Interest is credited");
overdraftAccount1.creditInterest();
System.out.println(overdraftAccount1);
System.out.println("\n--- Withdrawing --- ");
isSuccessful = overdraftAccount1.withdraw(500.0);
if (isSuccessful) { //will always return true
System.out.println("500.00 is withdrawn");
} else {
System.out.println("500.00 cannot be withdrawn because balance is not enough");
}
System.out.println(overdraftAccount1);
System.out.println(); // New line
isSuccessful = overdraftAccount1.withdraw(2000.0);
if (isSuccessful) { //will always return true
System.out.println("2000.0 is withdrawn");
} else {
System.out.println("2000.0 cannot be withdrawn because balance is not enough");
}
System.out.println(overdraftAccount1);
System.out.println(); // New line
OverdraftAccount overdraftAccount2 = new OverdraftAccount("O444-4444-444", "S2222222B", -2000);
System.out.println(overdraftAccount2);
System.out.println("\n--- Calculating and crediting interest for negative balances ---");
System.out.println("Interest: " + overdraftAccount2.calculateInterest());
System.out.println("Interest is credited");
overdraftAccount2.creditInterest();
System.out.println(overdraftAccount2);
System.out.println(); // New line
}
}