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 uses ARRAYS
  */
public class EmployeeV8 {
  
 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");
   final int SIZE = 100; // assume no more than 100 employees
   String[] names = new String[SIZE];
   double[]  hours = new double[SIZE];
   double[]  rates = new double[SIZE];
   int[] idnums = new int[SIZE];
   double[] grossPay = new double[SIZE];
   double[] taxes = new double[SIZE];
   double[] netPay = new double[SIZE];
   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
   int i=0;
   while (sc.hasNext()) {
      // Step 1: Read in idnum, name, hours, rate for employee
      idnums[i]=sc.nextInt();
      names[i] = sc.next();
      hours[i] = sc.nextDouble();
      rates[i] = sc.nextDouble();
      outFile.printf("%d    %-8s %5.2f %9.2f", 
                     idnums[i], names[i], hours[i], rates[i]);
      // Step 2: Calculate gross pay
      if (hours[i] <= 40) {
         grossPay[i] = hours[i] * rates[i];
      }
      else {
         grossPay[i] = 40 * rates[i] + (hours[i]-40)*1.5*rates[i];
      }
      // print gross pay
      outFile.printf("%11.2f", grossPay[i]);
      // Step 3: Subtract taxes from gross pay to get net pay
      if (grossPay[i] >= 1000){
         netPay[i] = grossPay[i] - .15 * grossPay[i];
      }
      else {
         netPay[i] = grossPay[i] - .10 * grossPay[i];
      }
      // print net pay
      outFile.printf("%12.2f", netPay[i]);
      outFile.println(); // goes to next line
      sum+=netPay[i];
      numEmployees++;
      i++;
   }// 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();
 }
}