Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective To write a program that parses and processes bank data from a file. PR

ID: 3789785 • Letter: O

Question

Objective        To write a program that parses and processes bank data from a file.

PROJECT DESCRIPTION

Bank has gotten their hands on some interesting data which will allow for possible loans to various clients from various regions.

Accompanying the labs specs is a csv (comma separated value) file named

bank-Detail.csv which contains valuable raw data to allow the bank to process loans based on client details from the file.

You need to parse the data and print record data for future loan considerations.

Project Details

           

-Create an abstract class called Client.java to allow for three abstract methods the bank needs to process. Name your methods readData(), processData() and printData().

-Create a BankRecords.java file which will utilize the Client asbtract methods and generate ultimately the client records from the csv file.

The client file has the following header information

            id {string}

           age {numeric}

            sex {FEMALE,MALE}

            region {INNER_CITY,TOWN,RURAL,SUBURBAN}

            income {numeric}

            married {NO,YES}

            children {0,1,2,3}

           car {NO,YES}

            save_act {NO,YES}

            current_act {NO,YES}

            mortgage {NO,YES}

            pep {YES,NO}

            Create instance fields for each header item above in your class.

            Include getter and setters for each instance field.

           

            -Include code definitions for each method declared in your Client class as follows

            Your readData() method should read in all the record data from the csv file in your path

            into an ArrayList.

Your processData() method should take all the record data from your ArrayList and add the data into each of your instance fields via your setters.

Your printData() method should print the first 25 records for various fields to the console via your getters. Print records for the following fields:

ID, AGE, SEX, REGION, INCOME, and MORTGAGE.

Include headings in your print detail.

Make sure to include a try catch block when reading any file!

Include your project’s entire source code into a zip file as well as your console output and source code into a doc file for credit.

Explanation / Answer

//Client.java

public abstract class Client { // Abstract class
   public abstract void readData(); // public Abstract method
   public abstract void processData(); // public Abstract method
   public abstract void printData(); // public Abstract method
}

//BankRecords.java

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Iterator;

public class BankRecords extends Client{ // Extending Abstract class and Overriding abstract methods

// Attributes of Banker

String id,sex,region;
   int age,income,children;
   String married,car,save_act,current_act,mortgage,pep;
  
   ArrayList<StringBuffer> list; // ArrayList Collection of type StringBuffer to store each record
  

// Setters and getters of above attributes
   public String getId() { //Getter
       return id;
   }

   public void setId(String id) { //Setter
       this.id = id;
   }

   public String getSex() {
       return sex;
   }

   public void setSex(String sex) {
       this.sex = sex;
   }

   public String getRegion() {
       return region;
   }

   public void setRegion(String region) {
       this.region = region;
   }

   public int getAge() {
       return age;
   }

   public void setAge(int age) {
       this.age = age;
   }

   public int getIncome() {
       return income;
   }

   public void setIncome(int income) {
       this.income = income;
   }

   public int getChildren() {
       return children;
   }

   public void setChildren(int children) {
       this.children = children;
   }

   public String getMarried() {
       return married;
   }

   public void setMarried(String married) {
       this.married = married;
   }

   public String getCar() {
       return car;
   }

   public void setCar(String car) {
       this.car = car;
   }

   public String getSave_act() {
       return save_act;
   }

   public void setSave_act(String save_act) {
       this.save_act = save_act;
   }

   public String getCurrent_act() {
       return current_act;
   }

   public void setCurrent_act(String current_act) {
       this.current_act = current_act;
   }

   public String getMortgage() {
       return mortgage;
   }

   public void setMortgage(String mortgage) {
       this.mortgage = mortgage;
   }

   public String getPep() {
       return pep;
   }

   public void setPep(String pep) {
       this.pep = pep;
   }

   @Override
   public void readData() {
       try{
       list = new ArrayList<StringBuffer>(); // Creating object for ArrayList
       FileReader fr = new FileReader("D:\bank-Detail.csv"); // REading File bank-Details from D: Drive
       BufferedReader br = new BufferedReader(fr); // Passing FileReader into BufferedReader
       String record;
      
       while((record=br.readLine())!=null){ // Accessing each record
           StringBuffer sb = new StringBuffer();
           sb.append(record); // Appending to StringBuffer
           list.add(sb); // Adding to ArrayList
       }
       } catch(Exception e){
           e.printStackTrace(); // Catching Exception
       }
   }

   @Override
   public void processData() {
       Iterator<StringBuffer> itr = list.iterator(); // Processing ArrayList using Iterator
       int i=0;
       while(itr.hasNext()){ // Iterating each record from list
           if(i==25){
               break;
           }
           StringBuffer sb = itr.next();
           String col[] = sb.toString().split(","); // Splitting each attribute with comma seperator
           this.setId(col[0]); // Setting each value to Setters
           this.setAge(Integer.parseInt(col[1]));
           this.setSex(col[2]);
           this.setRegion(col[3]);
           this.setIncome(Integer.parseInt(col[4]));
           this.setMortgage(col[10]);
           this.printData(); // Calling printData for every record
           i++;
       }
   }

   @Override
   public void printData() { // Printing records using getters
       System.out.println(this.getId()+" "+this.getAge()+" "+this.getSex()+" "+this.getRegion()+" "+this.getIncome()+" "+this.getMortgage());
      
   }
  
  
   public static void main(String[] args) {
      
       BankRecords bankRecords = new BankRecords(); // Creating object for records.
       bankRecords.readData(); // Calling readData method
       bankRecords.processData();
   }

}

SAMPLE DATA: (bank-Detail.csv)

501,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
502,28,MALE,INNER_CITY,25000,YES,2,YES,YES,NO,NO,YES
503,28,MALE,RURAL,15000,YES,2,YES,YES,NO,NO,YES
504,28,MALE,INNER_CITY,35000,YES,2,YES,YES,NO,NO,YES
505,28,MALE,TOWN,15000,YES,2,YES,YES,NO,NO,YES
506,28,MALE,SUBURBAN,15000,YES,2,YES,YES,NO,NO,YES
507,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
508,28,MALE,TOWN,15000,YES,2,YES,YES,NO,NO,YES
509,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
510,28,MALE,RURAL,15000,YES,2,YES,YES,NO,NO,YES
511,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
512,28,MALE,INNER_CITY,45000,YES,2,YES,YES,NO,NO,YES
513,28,MALE,TOWN,15000,YES,2,YES,YES,NO,NO,YES
514,28,MALE,INNER_CITY,45000,YES,2,YES,YES,NO,NO,YES
515,28,MALE,SUBURBAN,15000,YES,2,YES,YES,NO,NO,YES
516,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
517,28,MALE,INNER_CITY,25000,YES,2,YES,YES,NO,NO,YES
518,28,MALE,TOWN,15000,YES,2,YES,YES,NO,NO,YES
519,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
520,28,MALE,RURAL,15000,YES,2,YES,YES,NO,NO,YES
521,28,MALE,INNER_CITY,25000,YES,2,YES,YES,NO,NO,YES
522,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
523,28,MALE,RURAL,15000,YES,2,YES,YES,NO,NO,YES
524,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
525,28,MALE,INNER_CITY,15000,YES,2,YES,YES,NO,NO,YES
526,28,MALE,INNER_CITY,35000,YES,2,YES,YES,NO,NO,YES
527,28,MALE,SUBURBAN,35000,YES,2,YES,YES,NO,NO,YES

OUTPUT

501 28 MALE INNER_CITY 15000 NO
502 28 MALE INNER_CITY 25000 NO
503 28 MALE RURAL 15000 NO
504 28 MALE INNER_CITY 35000 NO
505 28 MALE TOWN 15000 NO
506 28 MALE SUBURBAN 15000 NO
507 28 MALE INNER_CITY 15000 NO
508 28 MALE TOWN 15000 NO
509 28 MALE INNER_CITY 15000 NO
510 28 MALE RURAL 15000 NO
511 28 MALE INNER_CITY 15000 NO
512 28 MALE INNER_CITY 45000 NO
513 28 MALE TOWN 15000 NO
514 28 MALE INNER_CITY 45000 NO
515 28 MALE SUBURBAN 15000 NO
516 28 MALE INNER_CITY 15000 NO
517 28 MALE INNER_CITY 25000 NO
518 28 MALE TOWN 15000 NO
519 28 MALE INNER_CITY 15000 NO