In this lab, you will read two files. Firstly, the ‘AccountData.csv’ file has the name and account number. Use each account number to scan the ‘BankData.csv’ file for a matching account number to get a ‘balance’ from the account transactions. You must repeatedly open, read the ‘BankData.csv’ file and close it for each account number in the ‘AccountData.csv’ file unless you wish to store its entire contents in a static array. (More code and may not be enough time to complete.)
In this lab, you will read two files. Firstly, the ‘AccountData.csv’ file has the name and account number.
Use each account number to scan the ‘BankData.csv’ file for a matching account number to get a ‘balance’
from the account transactions. You must repeatedly open, read the ‘BankData.csv’ file and close it for each
account number in the ‘AccountData.csv’ file unless you wish to store its entire contents in a static array.
(More code and may not be enough time to complete.)
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.time.format.DateTimeFormatter;
public class BankDataProcessing {
static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd-yyyy HH:mm");
static ArrayList<BankAccount> Accounts = new ArrayList<>();
public static void main(String[] args) {
try {
Path path = Paths.get("src/AccountData.csv");
readAccounts(path, true);
Path path2 = Paths.get("src/BankTransData.csv");
readTransactions(path, true, Accounts);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readAccounts(Path Xpath, boolean bHead) throws IOException {
BufferedReader bufferedReader = Files.newBufferedReader(Xpath);
try{
// open the 'path2' file with accounts 'AccountData.csv'
// code to process a String 'line' if header in file
//process remainder of 'AccountData.csv'
//split each line into a string array String[]=line.split.... //name,acctnum
//put informtiona into each object in the ArrayList
// of GLOBAL 'Accounts' variable of object datatype 'BankAccount'
}
catch (IOException ioe) {
bufferedReader.close();
ioe.printStackTrace();
}
finally {
bufferedReader.close();
}
}
private static void readTransactions(Path Xpath, boolean bHead, ArrayList<BankAccount> Xaccounts) throws IOException {
try{
// one big 'for each' loop to process each 'BankAccount' in ArrayList 'Xaccounts'
// test for header
// open the file using 'Xpath' and BufferedReader object
// split each line into a string array String[]=line.split.... // acctnum,date,transtype,amount
// print the "account name and number"
// while loop
// if "c" then Sting transtype is "Credit" else, "Debit"
// total all transactions for balance when current account number (from the 'for each loop')
// equals 'Xaccounts.getAcctnum' hint: use Integer.parseInt()
// print each transaction with proper "Credit" or "Debit" shown in sample output
//end while loop
// set balance in the specific 'Xaccounts' variable
// print the specific 'Xaccounts' element/object (uses the @Override in 'BankAcccount')
// CLOSE THE BufferedReader object
// end the for loop
}
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}

Trending now
This is a popular solution!
Step by step
Solved in 2 steps









