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 AND METHODS * (v7 uses arrays, v8 uses methods, v9 uses both. * v10 shows how values can be placed in an array in a method, * and be used back in the calling method */ public class EmployeeV10 { private static final int SIZE = 100; // assume no more than 100 employees public static void main(String[] args) throws IOException { // Declare all of the arrays 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[] netPay = new double[SIZE]; // Step 1: read in data int numEmps = readData(idnums, names, hours, rates); // Steps 2&3: Calculate gross pay and net pay calculatePay(hours, rates, grossPay, netPay, numEmps); // Step 4: Print all data printAllData(idnums, names, hours, rates, grossPay, netPay, numEmps); // Step 5: print sum of all net pays double sum = sumPay(netPay, numEmps); System.out.printf("We processed %d employees, Total pay is: $%.2f.\n", numEmps, sum); } /** this method reads in data about employees from a file * @param id id numbers * @param names array of String for names of employees * @param hrs hours worked * @param rts rate of pay per hour * @return number of data elts read in */ public static int readData(int[] id, String[] names, double[] hrs, double[] rts) throws IOException { Scanner sc = new Scanner(new File("employeeData.txt")); int count=0; // this will count the number of employees while (sc.hasNext() && count= 1000){ netPay[i] = grossPay[i] - .15 * grossPay[i]; } else { netPay[i] = grossPay[i] - .10 * grossPay[i]; } } } /** method sumPay receives an array representing net Pay and sums * all the values. * @param arr array to sum * @param size number of elts in array to be processed * @return sum of values as a double */ public static double sumPay(double[] arr, int size) { double sum=0.0; for (int i=0; i