-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMTester.java
More file actions
63 lines (51 loc) · 2.32 KB
/
ATMTester.java
File metadata and controls
63 lines (51 loc) · 2.32 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
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class ATMTester {
public static void main(String[] args) throws IOException {
ATM bank = new ATM();
int workingFunctions = 0;
try {
bank.openAccount("user1@example.com", 1000.0);
workingFunctions++;
bank.openAccount("user2@example.com", 500.0);
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.audit();
workingFunctions++;
System.out.println("Audit completed successfully.");
verifyAuditFile("AccountAudit.txt", 2);
} 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();
}
}
}