Question
IN Java I need help in doing the following: -Add to your existing project files from lab 2, a new class called Records . Have
IN Java I need help in doing the following:
-Add to your existing project files from lab 2, a new class called Records. Have the class extend the BankRecords class to grab hold of its instance methods plus the BankRecord object array.
-Provide at least 2comparator classes implementing the java.util.Comparatorinterfacefor comparing various fields for the following data analysis requirements.
-Perform the following analysis requirements and output detail for the Records class
Display the following data analyticsin a coherent manner to the console:
average income for males vs. females
number of females with a mortgage and savings account
number of males with both a car and 1 child per location
Write all displayed data to a text filecalled bankrecords.txt relative to your project path as well. Append your name within the text file at the end of the file plus the date/time.
These are the other existing files, the Client and Bank Records:
Client:
public abstract class Client {
abstract void readData();
abstract void processData();
abstract void PrintData();
//id, age, sex, etc.
String id;
int age;
String sex;
String regionset;
float income;
boolean married;
int childern;
boolean Car;
boolean sav_act;
boolean cur_act;
boolean mortgage;
boolean PEP;
public String Id() {
return id;
}
public void setId(String id) {
this.id = id;
}
public int theAge() {
return age;
}
public void Ageset(int age) {
this.age = age;
}
public String gettheSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String gettheRegion() {
return regionset;
}
public void setRegion(String regionset) {
this.regionset = regionset;
}
public float getIncome() {
return income;
}
public void setIncome(float f) {
this.income = f;
}
public boolean Married() {
return married;
}
public void marriedset(boolean areMarried) {
this.married = married;
}
public int getChildern() {
return childern;
}
public void Childernset(int childern) {
this.childern = childern;
}
public boolean Car() {
return Car;
}
public void setcar(boolean whoCar) {
this.Car = whoCar;
}
public boolean sav_act() {
return sav_act;
}
public void sav_act(boolean sav_act) {
this.sav_act = sav_act;
}
public boolean cur_act() {
return cur_act;
}
public void cur_act(boolean cur_act) {
this.cur_act = cur_act;
}
public boolean Mortgage() {
return mortgage;
}
public void setMortgage(boolean mortgage) {
this.mortgage = mortgage;
}
public boolean Pep() {
return PEP;
}
public void Pepset(boolean pep) {
this.PEP = pep;
}
}
Bank Records:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
public class BankRecords extends Client{
String csvFile = "D:/bank-Detail.csv";
BufferedReader breader = null;
String datalines = "";
ArrayList
BankRecords bankrecords[];
BankRecords(){
}
@Override
void readData() {
// TODO Auto-generated method stub
//read data from excel file
try{
breader = new BufferedReader(new FileReader(csvFile));
while ((datalines = breader.readLine()) != null) {
listofdata.add(datalines);
}
bankrecords= new BankRecords[listofdata.size()];
}
catch(Exception e){
System.out.println("exception: "+e);
}finally {
if (breader != null) {
try {
breader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
@Override
void processData() {
// TODO Auto-generated method stub
//bank records (income, children, etc.)
// true or false
for(int i=0;i String data[] = listofdata.get(i).split(","); bankrecords[i] = new BankRecords(); bankrecords[i].setId(data[0]); bankrecords[i].Ageset(Integer.parseInt(data[1])); bankrecords[i].setSex(data[3]); if(data[3].equals("town") || data[3].equals("rural") ) bankrecords[i].setRegion(data[3]+" "); // formatting of output else bankrecords[i].setRegion(data[5]); bankrecords[i].setIncome(Float.parseFloat(data[6])); if("YES".equals(data[7]) || "yes".equals(data[7])) bankrecords[i].marriedset(true); else bankrecords[i].marriedset(false); bankrecords[i].Childernset(Integer.parseInt(data[6])); if("YES".equals(data[7]) || "yes".equals(data[7])) bankrecords[i].setcar(true); else bankrecords[i].setcar(false); if("YES".equals(data[9]) || "yes".equals(data[9])) bankrecords[i].sav_act(true); else bankrecords[i].sav_act(false); if("YES".equals(data[10]) || "yes".equals(data[10])) bankrecords[i].cur_act(true); else bankrecords[i].cur_act(true); if("YES".equals(data[10]) || "yes".equals(data[10])) bankrecords[i].setMortgage(true); else bankrecords[i].setMortgage(false); if("YES".equals(data[10]) || "yes".equals(data[10])) bankrecords[i].Pepset(true); else bankrecords[i].Pepset(false); } } @Override void PrintData() { // TODO Auto-generated method stub //System.out.printf(id, age, sex, region, income, mortage) System.out.println("Number \t\t"+" id \t\t"+"age \t\t"+ "sex \t\t"+"region \t\t\t"+ "income \t\t" +"mortage \t\t"); for(int i=0;i<600;i++){ System.out.println( (i+1)+"\t\t"+bankrecords[i].Id()+"\t\t"+bankrecords[i].theAge()+"\t\t"+bankrecords[i].gettheSex()+"\t\t"+bankrecords[i].gettheRegion()+"\t\t"+bankrecords[i].getIncome()+"\t\t"+bankrecords[i].Mortgage()); } } public static void main(String args[]){ BankRecords bankrecord = new BankRecords(); bankrecord.readData(); bankrecord.processData(); bankrecord.PrintData(); }}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started