// 10/23/2017 /** The Payroll class calculates the Net Pay for two * employees. This is version 5 of the Payroll class. * This version uses a while loop illustrating different kinds * of conditions for terminating the loop. * * 1. read in a value * 2. ask the user if he/she wants to continue * 3. use sentinel * Algorithm for counting using a while loop * Validating input with while loop * Summing using a while loop * for loop */ import java.util.Scanner; public class Payroll5c { /** * pay is calculated by multiplying hours times rate, and * then subtracting 11% for taxes. */ public static void main(String[] args) { final double TAXES = .11; // employees pay 11% income tax double taxes=0.0, rate=0.0, pay=0.0; int hoursWorked=0; String name; Scanner readObject = new Scanner(System.in); int numEmployees=0; double totalPay=0.0; int idnum; System.out.print("Enter idnum (-1 to exit): "); idnum = readObject.nextInt(); // Structured Read Loop while (idnum !=-1) { readObject.nextLine(); // to skip newline in input buffer // prompt the user to enter a name System.out.print("Enter a name of employee: "); name = readObject.nextLine(); // prompt the user to enter data for hours and rate System.out.print("Enter number of hours worked and rate of pay: "); hoursWorked = readObject.nextInt(); rate = readObject.nextDouble(); pay = rate * hoursWorked; taxes = TAXES*pay; pay-=taxes; totalPay+=pay; // add this employee's pay to the total System.out.println("ID Name Hours Rate Pay"); System.out.println("----------------------------------"); System.out.printf("%d %s %4d $%4.2f $%,8.2f\n",idnum, name, hoursWorked, rate, pay); numEmployees++; readObject.nextLine(); // to skip newline in input buffer // end of loop read for Structured Read Loop System.out.print("Enter idnum (-1 to exit): "); idnum = readObject.nextInt(); } System.out.println("You entered " + numEmployees + " employees." + "\nTotal Pay is: " + totalPay); } } /* Lab assignment: Review: counting with while loop Review: writing methods Write a method that uses the while loop. The method should read in a number from the keyboard. The method will count how many numbers < the input number are divisible by 5. The method should return this number. Pseudocode for method: 1. read in a number 2. initialize divisor to 5 3. while (divisor < number) increment counter add 5 to divisor 4. return counter */