/* 10/2/2019
 Problem: given information about two Employees, calculate and print pay
 */
import java.util.Scanner;
import java.io.*;

/** This is version 4 of Payroll. 
  * uses input and output FILES
  */
public class PayrollV4 {
  
  /** read in: name, ID#, rate, hours
    * multiply rate*hours to get gross pay
    */
  public static void main(String[] args) throws IOException { 
    // we calculate gross pay
    double rate, hours, grossPay, netPay;
    String name;
    int idnum;
    Scanner sc = new Scanner(new File("employeeData.txt")); // gives us a Scanner object to help read
    PrintWriter outfile = new PrintWriter("payroll.txt");
    outfile.println("idnum name hours rate  gross pay   net pay");
    int numEmployees=0;
    double totalPay = 0.0;
    
    while (sc.hasNextInt()) {
       // read in 4 pieces of data per employee
       idnum = sc.nextInt();
       name = sc.nextLine();
       hours = sc.nextDouble();
       rate = sc.nextDouble();
       System.out.println("idnum: " + idnum + " name: " + name);
       System.out.println("hours: " + hours + " rate: " + rate);
       outfile.printf("%d %s %4.2f %4.2f   ", idnum, name, hours, rate);
       // if hours>40 give 1.5*rate for all overtime hours
       if (hours > 40) {
         grossPay = (hours-40)*rate*1.5+40*rate;
       }
       else {
         grossPay = rate * hours;
       }
       // rule for taxes, 25% off if salary is > 1000
       // 15% off otherwise
       double taxes;
       if (grossPay >= 1000) {
         taxes = .25*grossPay;
       }
       else {
         taxes = .15*grossPay;
       }
       netPay = grossPay - taxes;
       System.out.printf("gross pay: $%4.2f  net pay: $%4.2f\n",grossPay,netPay);  
       outfile.printf("%6.2f   %8.2f\n", grossPay, netPay);
       numEmployees++;
       totalPay+=grossPay; // totalPay = totalPay + grossPay;
    } // end while loop
    // fall out of while loop, print count and sum
    System.out.println("We processed " + numEmployees + " employees." +
                        " Total pay is " + totalPay);
    sc.close();
    outfile.close();
  }
}

/*** Lab 
  */



