-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATMTester.java
More file actions
55 lines (53 loc) · 2.08 KB
/
ATMTester.java
File metadata and controls
55 lines (53 loc) · 2.08 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
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("[email protected]", 1000);
workingFunctions++;
bank.openAccount("[email protected]", 500);
workingFunctions++;
bank.depositMoney("[email protected]", 200);
workingFunctions++;
bank.withdrawMoney("[email protected]", 100);
workingFunctions++;
bank.transferMoney("[email protected]", "[email protected]", 150);
workingFunctions++;
System.out.println("Balance for [email protected]: " +
bank.checkBalance("[email protected]")); // Should be
// 1050.0
workingFunctions++;
System.out.println("Balance for [email protected]: " +
bank.checkBalance("[email protected]")); // 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();
}
}
}