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

5.a. Create a program that accepts a series of employee ID number, first names,

ID: 3764034 • Letter: 5

Question

5.a. Create a program that accepts a series of employee ID number, first names, and last names from the keyboard and saves the data to a file. Save the program as WriteEmployeeList.java. When you execute the program, be sure to enter multiple records that have the same first name because you will search for repeated first names in part d of this exercise.

5.b. Write an application that reads the file created by the WriteEmployeeList application and displays the records. Save the file as DisplaySavedEmployeeList.java.

Explanation / Answer

import java.io.*;
import java.util.*;

public class WriteEmployeeList{
   public static void main(String[] args)
   {
  
   BufferedWriter bw=null;
try{
   bw=new BufferedWriter(new FileWriter("records.txt"));


Scanner s=new Scanner(System.in);
String x="y";
while(x.equals("Y")||x.equals("y")){

System.out.println("Enter Employeeid, First name, last name");
int id=s.nextInt();
String fname=s.next();
String lname=s.next();
String data=id+ " "+fname+" "+lname;
System.out.println(data);
bw.write(data);
System.out.println("Want more(Y/N)");
x=s.next();
}
bw.close();
}
catch ( Exception e) {
}
   }
}


****************************************************************

import java.io.*;
import java.util.*;

public class DisplaySavedEmployeeList{
   public static void main(String[] args)
   {
  
   BufferedReader br=null;
try{
   br=new BufferedReader(new FileReader("records.txt"));

System.out.println("EmpId    FirstName   LastName");
String output=br.readLine();
while(output!=null){
   System.out.println(output);
   output=br.readLine();
}
br.close();
}
catch ( Exception e) {
}
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote