/********************************/ // MR // Assignment 03_1 // Payroll // Date ... //********************************/ import java.io.*; import java.util.*; import java.text.*; public class Payroll { static final int ONE = 1; static final int DEDUCTION = 100; static final int DEPENDENT = 50; public static void main(String args[])throws Exception { Scanner console = new Scanner(System.in); System.out.print("Please enter an employee ID: "); int id = console.nextInt(); DecimalFormat idCheck = new DecimalFormat("000"); Scanner input = new Scanner(new File(idCheck.format(id) + "-hours.txt")); //Scanner input = new Scanner(new File(id + "-hours.txt")); SimpleDateFormat dateWeek = new SimpleDateFormat("MM/dd/yy"); Date payStarts = dateWeek.parse((String)input.next()); //String data = input.nextLine(); //Scanner rowOne = new Scanner(data); //pay period start and end GregorianCalendar end = new GregorianCalendar(); end.setTime(payStarts); end.add(Calendar.DAY_OF_YEAR, 4); Date payEnds = end.getTime(); //while (rowOne.hasNext()) { //String stdt = rowOne.next().toString();//5 days later???cal??? +4 String first = (String)input.next(); //String first = rowOne.next().toString(); //String mi = input.next().toString();//mi issues??? String mi = ""; //String last = rowOne.next().toString() ; //String last = (input.hasNextDouble()? "" : mi); //String last = (input.hasNextDouble() ? input.next().toString(): mi); //last = (input.hasNextDouble()? mi : input.next().toString()); String last = (String)input.next(); //first line.... double wage = input.nextDouble(); int dep = input.nextInt(); int ret = input.nextInt(); //hours for the week int hours = input.nextInt(); hours += input.nextInt(); hours += input.nextInt(); hours += input.nextInt(); hours += input.nextInt(); //System.out.println(hours); //while (rowOne.hasNextLine()){ //int day1 = rowOne.nextInt(); //int day2 = rowOne.nextInt(); //int day3 = rowOne.nextInt(); //int day4 = rowOne.nextInt(); //int day5 = rowOne.nextInt(); //int hours = (int)(day1 + day2 + day3 + day4 + day5); //for two decimal places in display DecimalFormat payCheck = new DecimalFormat("000.00"); //Hours and overtime calc double fortyHour = Math.min(0.0, hours); double overTime = Math.max(0.0, hours - fortyHour); double gross = (hours * wage) + (1.5 * wage * overTime); //retirement calc double retireDeduct = (gross - ret); //medical deduction calc retireDeduct -= (100.0 + (50.0 * dep)); //tax rate calc double taxRate = Math.max((0.18 - (0.02 * dep)), 0.0); //net pay calc double net = (Math.max((retireDeduct - taxRate * retireDeduct), 0.00)); //For todays date, line one //Calendar cal = Calendar.getInstance(); //System.out.println(); //makes a space between input and output //System.out.print(cal.get(Calendar.MONTH) + ONE + "/"); //System.out.print(cal.get(Calendar.DATE) + "/"); //System.out.print(cal.get(Calendar.YEAR)); //gives todays date //System.out.println(); //puts the date on its own line Date todaysDate = new Date(); //formatting date display SimpleDateFormat df = new SimpleDateFormat("MM/dd/yy"); System.out.println(df.format(todaysDate)); System.out.println("Pay to the order of " + (first + " " + mi + last) + ": $" + payCheck.format(net)); System.out.println("Memo: employee #" + id + " for the period of " + df.format(payStarts) + " through " + df.format(payEnds)); } }