I have been working on this problem but couldn't able to understand it properly. Can anyone explain me how should we approach? Thank you and appreciate your help.


Solution Code:
import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
class Result {
/*
* Complete the 'transform' function below.
*
* The function is expected to return an array of ints.
* The function accepts following parameters:
* 1. A List of Transaction objects
* 2. A Set of Strings
*/
public static int[] transform(List<Transaction> transactions, Set<String> categoriesRequested) {
}
}
public class Solution {
public static void main(String[] args) throws IOException {
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));
Scanner scanner = new Scanner(System.in);
List<Transaction> transactions = new ArrayList<>();
int totalTransactions = scanner.nextInt();
for (int i = 0 ; i < totalTransactions ; i++) {
transactions.add(new Transaction(scanner.nextInt(), scanner.nextBoolean(), scanner.next()));
}
Set<String> categoriesRequested = new LinkedHashSet<>();
int totalCategories = scanner.nextInt();
for (int i = 0 ; i < totalCategories ; i++) {
categoriesRequested.add(scanner.next());
}
int[] results = Result.transform(transactions, categoriesRequested);
for (int result : results) {
bufferedWriter.write(String.valueOf(result));
bufferedWriter.newLine();
}
bufferedWriter.close();
}
}
class Transaction {
private int amount;
private boolean credit;
private String category;
Transaction(int amount, boolean credit, String category) {
this.amount = amount;
this.credit = credit;
this.category = category;
}
public int getAmount() {
return amount;
}
public boolean isCredit() {
return credit;
}
public String getCategory() {
return category;
}
}