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

Description: A class Employee will have Name (String), city (String),state (Stri

ID: 3616986 • Letter: D

Question

Description:
A class Employee will have Name (String), city (String),state (String), and bonus (int).

There are two text files (FileA.text, FileB.txt) that list thenames of and unknown number of employees and their bonus for theprevious year. Assuming that these files are have exactly 4 linesper record i.e each employee’s information takes up exactlyfour lines:

EmployeeName
Street
City
Bonus

Problem:
The user will be prompted to choose either FileA or FileB andbasically the goal will be to read that text file using FileReader/BufferedReader. How do I instantiate each ofthe four lines as an Employee object and store into an ArrayList?And then be able to go through the arraylist to identify theemployee with the highest, lowest and the average bonus for theemployees and store as variables

Explanation / Answer

short which = 0; System.out.print("A or B? "); char ch = System.in.read(); if (ch == 'b' || ch == 'B')
   which = 1;
BufferedReader br;
if (which == 0)    br = new BufferedReader(newFileReader("FileA.txt")); else br = new BufferedReader(newFileReader("FileB.txt"));
ArrayList list = new ArrayList<Employee>(); String data = new String();
while (data != null){    for (short a=0; a<4; a++){    data =br.readLine();    switch (a){               case 0:       employee.Name = data;       break; //no case 1 because street isn't a member of the Employeeclass unless you need to differentiate between the same city fordifferent states...    case2:       employee.city = data;       data.toLowerCase();       switch(data){         case "columbus": case"canton"://cases for all the rest of the cities in Ohio       employee.state ="Ohio";       break;       //cases for the cities in Kentucky       employee.state ="Kentucky";       break;       //etc. for all the rest of thestates...       }       break;    case3:       employee.bonus = data;    }    data = null;    }    list.add(employee); } short which = 0; System.out.print("A or B? "); char ch = System.in.read(); if (ch == 'b' || ch == 'B')
   which = 1;
BufferedReader br;
if (which == 0)    br = new BufferedReader(newFileReader("FileA.txt")); else br = new BufferedReader(newFileReader("FileB.txt"));
ArrayList list = new ArrayList<Employee>(); String data = new String();
while (data != null){    for (short a=0; a<4; a++){    data =br.readLine();    switch (a){               case 0:       employee.Name = data;       break; //no case 1 because street isn't a member of the Employeeclass unless you need to differentiate between the same city fordifferent states...    case2:       employee.city = data;       data.toLowerCase();       switch(data){         case "columbus": case"canton"://cases for all the rest of the cities in Ohio       employee.state ="Ohio";       break;       //cases for the cities in Kentucky       employee.state ="Kentucky";       break;       //etc. for all the rest of thestates...       }       break;    case3:       employee.bonus = data;    }    data = null;    }    list.add(employee); } BufferedReader br;
if (which == 0)    br = new BufferedReader(newFileReader("FileA.txt")); else br = new BufferedReader(newFileReader("FileB.txt"));
ArrayList list = new ArrayList<Employee>(); String data = new String();
while (data != null){    for (short a=0; a<4; a++){    data =br.readLine();    switch (a){               case 0:       employee.Name = data;       break; //no case 1 because street isn't a member of the Employeeclass unless you need to differentiate between the same city fordifferent states...    case2:       employee.city = data;       data.toLowerCase();       switch(data){         case "columbus": case"canton"://cases for all the rest of the cities in Ohio       employee.state ="Ohio";       break;       //cases for the cities in Kentucky       employee.state ="Kentucky";       break;       //etc. for all the rest of thestates...       }    case3:       employee.bonus = data;    }    data = null;    }    list.add(employee); }