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.)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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();
        }
    }
    
}

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education