/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package lab2part5cwall; import java.util.Scanner; /** * * @author jcmtiernan */ public class Lab2Part5cwAll { /** * @param args the command line arguments */ public static void main(String[] args) { // Cannot put 0 on front of number in code // or it is interpreted as OCTAL not DECIMAL int exactStartTime = 0; int exactBreakStartTime = 0; int exactBreakEndTime = 0; int exactEndTime = 0; int recStartTime = 0; int recBreakStartTime = 0; int recBreakEndTime = 0; int recEndTime = 0; Scanner input = new Scanner(System.in); System.out.println("This system calculates a day's pay. It accepts \n" + "time in military format, 0000 to 2359. For each day there \n" + "will be a start time and an end time and there will also be \n" + "a break during the day with a start and end time. Please \n" + "enter the requested times in military format below.\n" + "If the time is before 10am, do not put the extra 0 on the\n" + "front of your military time, i.e. for 7:45am use 745, not 0745.\n\n"); System.out.println("Please enter the time you went on the clock for \n" + "the day in the format a 24-hour HHMM with no colon: "); exactStartTime = input.nextInt(); System.out.println("Please enter the time that you began your break: "); exactBreakStartTime = input.nextInt(); System.out.println("Please enter the time that you returned to work from \n" + "your break: "); exactBreakEndTime = input.nextInt(); System.out.println("Please enter the time that you ended your work day: "); exactEndTime = input.nextInt(); // no error checking is done on input int min = exactStartTime % 100; int retTime = exactStartTime - min; if ((min >= 0) && (min <= 7)) { min = 0; } else if ((min >= 8) && (min <= 22)) { min = 15; } else if ((min >= 23) && (min <= 37)) { min = 30; } else if ((min >= 38) && (min <= 52)) { min = 45; } else if ((min >= 53) && (min <= 59)) { min = 100; } else { min = 0; // minute value was greater than 59 } retTime = retTime + min; if (retTime > 2359) { retTime = 0; } recStartTime = retTime; min = exactBreakStartTime % 100; retTime = exactBreakStartTime - min; if ((min >= 0) && (min <= 7)) { min = 0; } else if ((min >= 8) && (min <= 22)) { min = 15; } else if ((min >= 23) && (min <= 37)) { min = 30; } else if ((min >= 38) && (min <= 52)) { min = 45; } else if ((min >= 53) && (min <= 59)) { min = 100; } else { min = 0; // minute value was greater than 59 } retTime = retTime + min; if (retTime > 2359) { retTime = 0; } recBreakStartTime = retTime; min = exactBreakEndTime % 100; retTime = exactBreakEndTime - min; if ((min >= 0) && (min <= 7)) { min = 0; } else if ((min >= 8) && (min <= 22)) { min = 15; } else if ((min >= 23) && (min <= 37)) { min = 30; } else if ((min >= 38) && (min <= 52)) { min = 45; } else if ((min >= 53) && (min <= 59)) { min = 100; } else { min = 0; // minute value was greater than 59 } retTime = retTime + min; if (retTime > 2359) { retTime = 0; } recBreakEndTime = retTime; min = exactEndTime % 100; retTime = exactEndTime - min; if ((min >= 0) && (min <= 7)) { min = 0; } else if ((min >= 8) && (min <= 22)) { min = 15; } else if ((min >= 23) && (min <= 37)) { min = 30; } else if ((min >= 38) && (min <= 52)) { min = 45; } else if ((min >= 53) && (min <= 59)) { min = 100; } else { min = 0; // minute value was greater than 59 } retTime = retTime + min; if (retTime > 2359) { retTime = 0; } recEndTime = retTime; // need to deal with minutes seperately out of 60 not out of 100 int rBSTm = recBreakStartTime % 100; int rBSTh = recBreakStartTime - rBSTm; int rSTm = recStartTime % 100; int rSTh = recStartTime - rSTm; int firstHalf = (rBSTh - rSTh) + (rBSTm - rSTm); if ((rBSTm - rSTm) < 0) { // 1600 - 1215 gives 385 but should give 345 so firstHalf = firstHalf - 40; } int rBETm = recBreakEndTime % 100; int rBETh = recBreakEndTime - rBETm; int rETm = recEndTime % 100; int rETh = recEndTime - rETm; int secondHalf = (rETh - rBETh)+(rETm - rBETm); if ((rETm - rBETm) < 0) { secondHalf = secondHalf - 40; } // need to check for min value over 45 and handle int day = firstHalf + secondHalf; if ((day % 100) > 45) { day = (day - 60) + 100; // minus a 60 minute hour and add 100 to record the hour } // Convert HHMM total to HH.hh double hoursPay = ((day / 100) + (((day % 100)/15) * .25)); double hoursRate = 8.25; double totalPay = hoursPay * hoursRate; System.out.printf("%8s%8s%8s%8s%8s\n","Time ","","Start","End",""); System.out.printf("%8s%8s%8s%8s%8s\n","Data:","Start","Break","Break","End"); System.out.printf("%8s%8d%8d%8d%8d\n","Exact",exactStartTime,exactBreakStartTime,exactBreakEndTime,exactEndTime); System.out.printf("%8s%8d%8d%8d%8d\n\n","Recorded",recStartTime,recBreakStartTime,recBreakEndTime,recEndTime); System.out.printf("%8s%8s\n%8s%8d\n","","Total","hhmm",day); System.out.printf("%8s%8d\n%8s%8d\n\n","Hours &",(day/100),"Minutes",(day%100)); System.out.printf("%8s%8.2f\n%8s%8.2f%8s\n","As hours",hoursPay,"At rate",hoursRate," per hour"); System.out.printf("%7s%1s%8.2f\n\n","Pay ","$",totalPay); } }