-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExchangeReportGenerator.java
More file actions
37 lines (31 loc) · 1.29 KB
/
Copy pathExchangeReportGenerator.java
File metadata and controls
37 lines (31 loc) · 1.29 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
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;
public class ExchangeReportGenerator {
public static Map<String, String> rows = new HashMap<String, String>();
public static void addFailedPolicy(String orderID, String reason) {
ExchangeReportGenerator.rows.put(orderID, reason);
}
public static void generateCSVFile() {
try (FileWriter csvWriter = new FileWriter("C:\\Users\\USER\\Documents\\BOFA\\CodeToConnect2024\\output_exchange_report.csv")) {
// Write header row
csvWriter.append("Order Id,Rejection Reason\n");
// Write data row
// Iterating HashMap through forEach and
// Printing all. elements in a Map
for (Map.Entry<String, String> set : rows.entrySet()) {
csvWriter.append(set.getKey()).append(",").append(set.getValue()).append("\n");
}
// Close the csvWriter to save the data
csvWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ExchangeReportGenerator.addFailedPolicy("D1" ,"REJECTED – MISMATCH CURRENCY");
ExchangeReportGenerator.addFailedPolicy("B2" ,"REJECTED – INVALID LOT SIZE");
ExchangeReportGenerator.addFailedPolicy("C2" ,"REJECTED – POSITION CHECK FAILED");
ExchangeReportGenerator.generateCSVFile();
}
}