I need to write a java program in Eclipse Indigo with the scenario that three em
ID: 3641056 • Letter: I
Question
I need to write a java program in Eclipse Indigo with the scenario that three employees in a company are up for a special pay increase. I am given a file, say Ch3_Ex7Data.text, with the following data:Miller Andrew 65789.87 5
Green Sheila 75892.56 6
Sethi Amit 74900.50 6.1
Each input line consists of an employee’s last name, first name, current salary, and percent pay increase. For example, in the first input line, the last name of the employee is Miller, the last name is Andrew, the current salary is 65789.87, and the pay increase is 5%. The program that I need to write reads data from the specified file and stores the output in the file Ch3_Ex7Output.dat For each employee, the data must be output in the following form: firstName lastName updateSalary. Format the output of decimal numbers to two decimal places.
Explanation / Answer
import java.io.PrintWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class Program {
public static void main(String[] args) throws IOException {
String inFileName = "Ch3_Ex7Data.txt"; //your input file name here
String outFileName = "Ch3_Ex7Output.dat"; //your output file name here
String lastName;
String firstName;
double salary;
double payIncrease;
double newSalary;
Scanner in = new Scanner(new FileReader(inFileName));
PrintWriter out = new PrintWriter(new FileWriter(outFileName));
while (in.hasNext()) {
lastName = in.next();
firstName = in.next();
salary = in.nextDouble();
payIncrease = in.nextDouble();
newSalary = salary * (1.0 + payIncrease / 100.0);
String line = String.format("%s %s %.2f", firstName, lastName, newSalary);
out.println(line);
}
in.close();
out.close();
System.out.println("Successfully write pay increases to " + outFileName);
}
}