/**************************** BS Assignment 3 Problem 1 What it does: Reads from a file given an employee number and calculates the pay check. ****************************/ import java.io.*; import java.util.GregorianCalendar; import java.util.*; public class Payroll { public static void main(String args[]) throws Exception{ String zero = "0"; String doubleZero = "00"; int medicalDeduction = 100; int medicalDeductionDependant = 50; System.out.print("Employee Number?: "); Scanner input = new Scanner(System.in); String employeeNumber = input.nextLine(); String employeeFile = ""; employeeFile = employeeNumber.length() == 1 ? employeeFile.concat(doubleZero.concat(employeeNumber.concat("-hours.txt"))) : (employeeNumber.length() == 2 ? employeeFile.concat(zero.concat(employeeNumber.concat("-hours.txt"))) : (employeeNumber.length() >= 3 ? employeeFile.concat(employeeNumber.concat("-hours.txt")) : "")); Scanner fileInSystem = new Scanner(new File(employeeFile)); String line = fileInSystem.nextLine(); Scanner line_1 = new Scanner(line); String payPeriod = line_1.next().toString(); String firstName = line_1.next().toString(); //String midInit = line_1.next().toString(); String midInit = ""; String lastName = midInit = (line_1.hasNextInt() ? "" : midInit); lastName = (line_1.hasNextInt() ? midInit : line_1.next().toString()); float wage = line_1.nextFloat(); int dependents = line_1.nextInt(); int preTaxAmount = line_1.nextInt(); //System.out.println("payPeriod " + payPeriod); //System.out.println("firstName " + firstName); //System.out.println("lastName " + lastName); //System.out.println("wage " + wage); //System.out.println("dependents " + dependents); //System.out.println("preTaxAmount " + preTaxAmount); double hours = 0.0; while(fileInSystem.hasNextLine()){ String day = fileInSystem.nextLine(); Scanner nextLine = new Scanner(day); hours += nextLine.nextFloat(); } //System.out.println("hours " + hours); hours = hours > 40 ? (40 + (hours - 40) * 1.5) : hours; double grossPay = hours * wage; double taxableIncome = grossPay - preTaxAmount - medicalDeduction - (medicalDeductionDependant * dependents); taxableIncome = taxableIncome > 0 ? taxableIncome : 0; double taxRate = (18 - (dependents * 2)) > 0 ? (18 - (dependents * 2)) : 0; double tax = taxableIncome * (taxRate/100); double netPay = (taxableIncome - tax) > 0 ? (taxableIncome - tax) : 0; /*System.out.println("hours after overtime" + hours); System.out.println("grossPay " + grossPay); System.out.println("taxableIncome " + taxableIncome); System.out.println("taxRate " + taxRate); System.out.println("tax " + tax); System.out.println("netPay " + netPay);*/ String[] ids = TimeZone.getAvailableIDs(-8 * 60 * 60 * 1000); if (ids.length == 0){ System.exit(0); } SimpleTimeZone pdt = new SimpleTimeZone(-8 * 60 * 60 * 1000, ids[0]); pdt.setStartRule(Calendar.APRIL, 1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); pdt.setEndRule(Calendar.OCTOBER, -1, Calendar.SUNDAY, 2 * 60 * 60 * 1000); Calendar calendar = new GregorianCalendar(pdt); Date now = new Date(payPeriod); calendar.setTime(now); //calendar.add(Calendar.MONTH, 1); //System.out.println(calendar.get(Calendar.MONTH) + "/" + calendar.get(Calendar.DATE) + "/" + calendar.get(Calendar.YEAR)); System.out.println(payPeriod); System.out.println("Pay to the order of " + firstName + " " + midInit + lastName + ": $" + netPay); System.out.print("Memo: employee #" + employeeNumber + " for the period "); //System.out.print(calendar.get(Calendar.MONTH) + "/" + calendar.add(calendar.get(Calendar.DATE), -14) + "/" + calendar.get(Calendar.YEAR)); System.out.print("through"); //System.out.println(calendar.get(Calendar.MONTH) + "/" + calendar.add(calendar.get(Calendar.DATE), -7) + "/" + calendar.get(Calendar.YEAR)); return ; } }