/* 11/6/2019 Problem: given information about two Employees, calculate and print pay */ import java.util.Scanner; import java.io.*; /** This is version 5 of Payroll. * use partially filled ARRAYS * we will count the # of employees being read in. */ public class PayrollV5b { /** read in: name, ID#, rate, hours * multiply rate*hours to get gross pay */ public static void main(String[] args) throws IOException { final int SIZE = 100; // we calculate gross pay double[] rates = new double[SIZE]; double[] hours = new double[SIZE]; double[] grossPay = new double[SIZE]; double[] netPay = new double[SIZE]; String[] names = new String[SIZE]; int[] idnums = new int[SIZE]; int numEmps=0; double totalPay = 0.0; Scanner sc = new Scanner(new File("employeeData.txt")); // gives us a Scanner object to help read while (sc.hasNextInt() && numEmps < SIZE) { // read in 4 pieces of data per employee idnums[numEmps] = sc.nextInt(); names[numEmps] = sc.nextLine(); hours[numEmps] = sc.nextDouble(); rates[numEmps] = sc.nextDouble(); // if hours>40 give 1.5*rate for all overtime hours if (hours[numEmps] > 40) { grossPay[numEmps] = (hours[numEmps]-40)*rates[numEmps]*1.5+40*rates[numEmps]; } else { grossPay[numEmps] = rates[numEmps] * hours[numEmps]; } // rule for taxes, 25% off if salary is > 1000 // 15% off otherwise double taxes; if (grossPay[numEmps] >= 1000) { taxes = .25*grossPay[numEmps]; } else { taxes = .15*grossPay[numEmps]; } netPay[numEmps] = grossPay[numEmps] - taxes; totalPay+=netPay[numEmps]; // totalPay is total of Net Pay numEmps++; } // end while loop // fall out of while loop, print count and sum System.out.println("We processed " + numEmps + " employees." + " Total pay is " + totalPay); // show that data is still available // outside of while loop PrintWriter outfile = new PrintWriter("payroll.txt"); outfile.println("idnum name hours rate gross pay net pay"); for (int i=0; i