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

Using Java a. Create a program that accepts a series of employee ID numbers, fir

ID: 657520 • Letter: U

Question

Using Java

a. Create a program that accepts a series of employee ID numbers, 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.
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.nio.file.*;
import java.io.*;
import static java.nio.file.StandardOpenOption.*;
import java.util.Scanner;
public class WriteEmployeeFile
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Path file =
Paths.get("C:\Java\Chapter\Employees.txt");
String s = "";
String delimiter = ",";
int id;
String name;
double payRate;
final int QUIT = 999;
try
{
OutputStream output = new
BufferedOutputStream(Files.newOutputStream(file, CREATE));
BufferedWriter writer = new
BufferedWriter(new OutputStreamWriter(output));
System.out.print("Enter employee ID number >> ");
id = input.nextInt();
while(id != QUIT)
{
System.out.print("Enter name for employee #" +
id + " >> ");
input.nextLine();
name = input.nextLine();
System.out.print("Enter pay rate >> ");
payRate = input.nextDouble();
s = id + delimiter + name + delimiter + payRate;
writer.write(s, 0, s.length());
writer.newLine();
System.out.print("Enter next ID number or " +
QUIT + " to quit >> ");
id = input.nextInt();
}
writer.close();
}
catch(Exception e)
{
System.out.println("Message: " + e);
}
}
}

import java.nio.file.*;
import java.io.*;
public class ReadEmployeeFile
{
public static void main(String[] args)
{
Path file =
Paths.get("C:\Java\Chapter\Employees.txt");
String s = "";
try
{
InputStream input = new
BufferedInputStream(Files.newInputStream(file));
BufferedReader reader = new
BufferedReader(new InputStreamReader(input));
s = reader.readLine();
while(s != null)
{
System.out.println(s);
s = reader.readLine();
}
reader.close();
}
catch(Exception e)
{
System.out.println("Message: " + 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