Question: Using Java, I am trying to read in a file with the format outlined below. AARON, ELVIA J WATER RATE TAKER WATER MGMNT $87,228.00 AARON,

Using Java, I am trying to read in a file with the format outlined below.

"AARON, ELVIA J" WATER RATE TAKER WATER MGMNT "$87,228.00" "AARON, JEFFERY M" POLICE OFFICER POLICE "$75,372.00" "AARON, KARINA" POLICE OFFICER POLICE "$75,372.00" "AARON, KIMBERLEI R" CHIEF CONTRACT EXPEDITER GENERAL SERVICES "$80,916.00" "ABAD JR, VICENTE M" CIVIL ENGINEER IV WATER MGMNT "$99,648.00" "ABARCA, ANABEL" ASST TO THE ALDERMAN CITY COUNCIL "$70,764.00" "ABARCA, EMMANUEL" GENERAL LABORER - DSS STREETS & SAN "$40,560.00" "ABBATACOLA, ROBERT J" ELECTRICAL MECHANIC AVIATION "$89,440.00" "ABBATEMARCO, JAMES J" FIRE ENGINEER FIRE "$84,396.00" "ABBATE, TERRY M" POLICE OFFICER POLICE "$80,724.00" "ABBOTT, BETTY L" FOSTER GRANDPARENT FAMILY & SUPPORT "$2,756.00" "ABBOTT, LYNISE M" CLERK III POLICE "$41,784.00" "ABBRUZZESE, WILLIAM J" INVESTIGATOR - IPRA II IPRA "$65,808.00" "ABDALLAH, ZAID" POLICE OFFICER POLICE "$65,016.00" "ABDELHADI, ABDALMAHD" POLICE OFFICER POLICE "$75,372.00" "ABDELLATIF, AREF R" FIREFIGHTER (PER ARBITRATORS AWARD)-PARAMEDIC FIRE "$90,738.00" "ABDELMAJEID, AZIZ" POLICE OFFICER POLICE "$75,372.00" "ABDOLLAHZADEH, ALI" PARAMEDIC I/C FIRE "$81,672.00" "ABDUL-KARIM, MUHAMMAD A" ENGINEERING TECHNICIAN VI WATER MGMNT "$96,384.00" "ABDULLAH, ASKIA" LEGISLATIVE AIDE CITY COUNCIL "$25,008.00"

The problem I am having is in splitting the file between arrays. The first array has the name example: AARON, ELVIA J ( with or without the comma makes no difference). The second array hold the department and position example: WATER RATE TAKER WATER MGMT. The third array holds the salary as a double example: 87228.00. The code I have so far is below,MY ERROR IS OCCURING AT LINE 33 (String tempName = tokenize[1];) . I need to know how to fix the error and what I am doing wrong. The arrays also need to line up so I can match the index places with the correct records example index 0 in each array contains the information for the same person. If I am going about this all wrong please tell me a better way.

import java.io.*; import java.util.*; public class PA3 { String name; String position; double salary; public PA3(String name, String position, double salary){ this.name = name; this.position = position; this.salary = salary; } // end constructor

public static void main(String[] args) throws Exception { ArrayList employee = new ArrayList(); try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("empl.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println (strLine); // split the data by the quotation marks int three separate arrays using string tokenizer String[] tokenize = strLine.split(" "); // first split with 4 spaces String tempName = tokenize[1]; // name is split and moved to array String tempPosition = tokenize[2]; // position is split and moved to array String temp = (tokenize[3].replace("$","").replace(",","").replace("\"","")); //replace all unwanted characters double tempSalary = Double.parseDouble(temp); // parse string temp to double PA3 tempObject = new PA3(tempName, tempPosition, tempSalary); //creates object with data employee.add(tempObject); } // end while in.close(); //Close the input stream } // end try catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } // end catch } // end main } // end class

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!