import java.util.Scanner; import java.io.*; /** The Employee class will read in info about any number of * employees and caculate * the weekly salary for each employee. * This version reads until the end of the input by calling * hasNext() * using FILES */ public class EmployeeV6 { public static void main(String[] args) throws IOException { int numEmployees=0; // this will count the number of employees Scanner sc = new Scanner(new File("employeeData.txt")); PrintWriter outFile = new PrintWriter("employeePay.txt"); String name; double hours, rate; int idnum; double sum=0.0; // write headings to file outFile.println("ID Name Hours Rate Gross Pay Net Pay"); // while there is data to be read while (sc.hasNext()) { // Step 1: Read in idnum, name, hours, rate for employee 1 idnum=sc.nextInt(); name = sc.next(); hours = sc.nextDouble(); rate = sc.nextDouble(); outFile.printf("%d %-8s %5.2f %9.2f", idnum, name, hours, rate); // Step 2: Calculate gross pay double pay; if (hours <= 40) { pay = hours * rate; } else { pay = 40 * rate + (hours-40)*1.5*rate; } // print gross pay outFile.printf("%11.2f", pay); // Step 3: Subtract taxes from pay if (pay >= 1000){ pay -= .15 * pay; } else { pay -= .10 * pay; } // print net pay outFile.printf("%12.2f", pay); outFile.println(); // goes to next line sum+=pay; numEmployees++; }// end while loop // after fall out of while loop, print the number of employees and total pay System.out.printf("We processed %d employees, Total pay is: $%.2f.\n", numEmployees, sum); sc.close(); outFile.close(); } }