-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMTester.java
More file actions
76 lines (59 loc) · 2.73 KB
/
ATMTester.java
File metadata and controls
76 lines (59 loc) · 2.73 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ATMTester {
public static void main(String[] args) {
ATM bank = new ATM();
int workingFunctions = 0;
try {
bank.openAccount("user1@example.com", 1000);
workingFunctions++;
bank.openAccount("user2@example.com", 500);
workingFunctions++;
bank.depositMoney("user1@example.com", 200);
workingFunctions++;
bank.withdrawMoney("user2@example.com", 100);
workingFunctions++;
bank.transferMoney("user1@example.com", "user2@example.com", 150);
workingFunctions++;
System.out.println("Balance for user1@example.com: " + bank.checkBalance("user1@example.com")); // Should be
// 1050.0
workingFunctions++;
System.out.println("Balance for user2@example.com: " + bank.checkBalance("user2@example.com")); // Should be
// 550.0
workingFunctions++;
bank.openAccount("user101@aol.com", 42069);
bank.openAccount("user102@aol.com", 2);
bank.openAccount("user103@aol.com", 1010);
bank.openAccount("user104@aol.com", 389);
bank.openAccount("user105@aol.com", 2389);
bank.withdrawMoney("user103@aol.com",bank.checkBalance("user103@aol.com"));
bank.closeAccount("user103@aol.com");
bank.transferMoney("user101@aol.com", "user102@aol.com", 69);
bank.audit();
workingFunctions++;
System.out.println("Audit completed successfully.");
verifyAuditFile("AccountAudit.txt", 6);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println("Valid Use Cases: " + workingFunctions);
}
}
private static void verifyAuditFile(String fileName, int expectedEntries) {
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
int entryCount = 0;
while (reader.readLine() != null) {
entryCount++;
}
if (entryCount == expectedEntries) {
System.out.println("Audit file entries match expected count.");
} else {
System.out.println(
"Audit file entries" + entryCount + "do not match expected count" + expectedEntries + ".");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}