Question: I am having trouble, the code I have below seems to be computing total grossSalary of all employees in file together rather than individually, same

I am having trouble, the code I have below seems to be computing total grossSalary of all employees in file together rather than individually, same with taxes and net income. I need it to do it individually as well as totaling it all at the end of the output file. It should display in order to the file payRoll.txt : firstName: lastName: payRate: hoursWorked: grossSalary: Taxes: netIncome: and then at the end it should write to the file, number of employees processed: sum of all salaries: sum of all taxes: sum of netIncome:

I reallly just need help with how to get the totals individually from each employee within the text file.

Q: Your program should then read one employee at a time, compute their grossSalary(hoursWorked*payRate), taxes (taxRate*grossSalary), and netIncome (grossSalary-taxes). The programs should produce the payroll information to the output file named payroll.txt. The program should use the following payRate table to compute taxes: package employeeTXT;

import java.io.*;

import java.util.*;

import javax.swing.*;

public class Assignment1 { public static void main(String[] args) throws IOException {

String fileName;

String firstName;

String lastName;

int hoursWorked, payRate, grossSalary;

double netIncome; int countOfEmployees;

fileName = JOptionPane.showInputDialog("Enter the name of the file that holds employee information");

countOfEmployees = Integer.parseInt(JOptionPane.showInputDialog("Enter the number of students in the file"));

Scanner inFile = new Scanner(new FileReader("\\Users\\sever2845\\workspace\\" + fileName + ".txt"));

PrintWriter outFile = new PrintWriter("\\Users\\sever2845\\workspace\\" + fileName + "-out.txt");

for (int i = 1; i <=countOfEmployees; i++) {

firstName = inFile.next();

lastName = inFile.next();

hoursWorked = inFile.nextInt();

payRate = inFile.nextInt();

JOptionPane.showMessageDialog(null, String.format("Processing %s%s \t%d%d ", firstName, lastName, hoursWorked, payRate), "Processing", JOptionPane.INFORMATION_MESSAGE);

BufferedWriter bw = new BufferedWriter(new FileWriter("\\Users\\sever2845\\workspace\\payroll.txt"));

grossSalary = hoursWorked * payRate; double taxes;

if(grossSalary < 250) taxes = 0.18 * grossSalary;

else if(grossSalary < 550) taxes = 0.23 * grossSalary;

else if(grossSalary < 1100) taxes = 0.28 * grossSalary;

else taxes = 0.33 * grossSalary; netIncome = grossSalary - taxes;

bw.write("Employee " + String.valueOf(i) + " ");

bw.write("Gross Salary = " + String.valueOf(grossSalary)+ " ");

bw.write("Taxes = " + String.valueOf(taxes)+ " "); bw.write("Net Income = " + String.valueOf(netIncome)+ " "); bw.close();

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!