/* Examples of loops */ package fifthfall16; import java.util.Scanner; /** * * @author jcmtiernan */ public class FifthFall16 { /** * @param args the command line arguments */ public static void main(String[] args) { double hoursWorked; double fullWeekMax = 40.0; double fullWeekMin = 37.0; double moreHours = 0.0; Scanner input = new Scanner(System.in); int weeksInMonth; int weekCounter = 0; boolean validWeeks = true; double payPerHour = 12.50; double overtimeRate = 1.5; double totalPay = 0; System.out.print("Please entered the number of weeks you worked this month: "); weeksInMonth = input.nextInt(); /* Error check and save results in validWeeks*/ if ((weeksInMonth < 0) || (weeksInMonth > 4)) { validWeeks = false; } if (validWeeks) { for (weekCounter =1 ;weekCounter <= weeksInMonth; weekCounter++ ) { System.out.print("Please entered the hours you worked in week " +weekCounter+" this month: "); hoursWorked = input.nextDouble(); // We should error check the number of hours /* if ((weeksInMonth >= 0)&& (weeksInMonth <=4)) //((weeksInMonth < 0) || (weeksInMonth > 4)) { */ if (hoursWorked > fullWeekMax) { // true result Overtime totalPay += (fullWeekMin * payPerHour) + ((hoursWorked- fullWeekMin )* overtimeRate * payPerHour); // 40 hours payPerHour plus 1.5 * hours over 40 } else if (hoursWorked < fullWeekMin) { // true result Partial totalPay += hoursWorked * payPerHour;// hours * payPerHour } else { // else Regular totalPay += hoursWorked * payPerHour; // 40 hours payPerHour } //} } System.out.println("Total pay for "+weeksInMonth+" weeks is "+totalPay); } else { System.out.println("You entered an invalid number of weeks"); } do { System.out.println("Reducing weekCounter "+weekCounter); weekCounter--; } while (weekCounter > 0); } }