In: Computer Science
Three employees in a company are selected for a pay increase. You are given a file (salaries.txt) that contains three lines. Each line in the file consists of an employee’s last name, first name, current salary, and percent pay increase. For example, in the first line, the last name of the employee is Miller, the first name is Andrew, the current salary is 65789.87 and the pay increase is 5%. Write a program that reads data from the file and stores the output in another file. The output data must be in the following format: FirstNameInitial lastName updatedSalary Format the output of decimal number to two decimal places. For example, the first line in the output may look like the following: A. Miller 69079.36 I want help to solve it on netbeans
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try (FileReader reader = new FileReader("salaries.txt");
BufferedReader br = new BufferedReader(reader)) {
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
String[] inputs = line.split(" ");
String lastName = inputs[0];
String firstName = inputs[1];
double salary = Double.parseDouble(inputs[2]);
double raise = Double.parseDouble(inputs[3]);
double newSalary = (1 + raise/100) * salary;
System.out.println(String.format("%c. %s %.2f\n", Character.toUpperCase(firstName.charAt(0)), lastName, newSalary));
try (FileWriter writer = new FileWriter("output.txt", true);
BufferedWriter bw = new BufferedWriter(writer)) {
bw.write(String.format("%c. %s %.2f\n", Character.toUpperCase(firstName.charAt(0)), lastName, newSalary));
} catch (IOException e) {
System.err.format("IOException: %s%n", e);
}
}
} catch (IOException e) {
System.err.format("error occurred while opening the file", e);
}
}
}