/* * Intro to Programming CSE 1310 * University of Texas at Arlington */ package code24oct17lab2; import java.util.Scanner; /** * * @author jcmtiernan */ public class Code24Oct17Lab2 { /** * @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(); // error checking is done on input exactStartTime exactStartTime = errorCheck(exactStartTime); // rounding for exactStartTime // put into it is exactStartTime and get out recStartTime recStartTime = rounding(exactStartTime); // put into it is exactBreakStartTime and get out recBreakStartTime exactBreakStartTime = errorCheck(exactBreakStartTime); recBreakStartTime = rounding(exactBreakStartTime); // put into it is exactBreakEndTime and get out recEndTime exactBreakEndTime = errorCheck(exactBreakEndTime); recBreakEndTime = rounding(exactBreakEndTime); // put into it is exactEndTime and get out recEndTime exactEndTime = errorCheck(exactEndTime); recEndTime = rounding(exactEndTime); // 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); } public static int rounding(int exactTime) { int recordedTime = 0; int min = exactTime % 100; int retTime = exactTime - 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; } recordedTime = retTime; return recordedTime; } public static int errorCheck(int exactTime) { int mm = exactTime % 100; int hh = exactTime / 100; if (exactTime < 0) // || (h == 24) invalid hour 24; check for negative value { hh = 0; if (mm < 0) { mm = -mm; } } if (mm > 59) { mm = mm - 60; hh = hh + 1; // hh++; } if (hh >= 24) { hh = hh % 24; } exactTime = hh * 100 + mm; return exactTime; } }