/* 9/23/2019 Problem: given information about two Employees, calculate and print pay */ import java.util.Scanner; /** This is version 3 of Payroll. We use structured read loop with a sentinel, * Count and Sum are in here, names of variables are * numEmployees and * totalPay */ public class PayrollV3 { /** read in: name, ID#, rate, hours * multiply rate*hours to get gross pay */ public static void main(String[] args) { // we calculate gross pay double rate, hours, grossPay, netPay; String name; int idnum; Scanner sc = new Scanner(System.in); // gives us a Scanner object to help read int numEmployees=0; double totalPay = 0.0; // structured read loop System.out.println("Enter id number, -1 to finish"); idnum = sc.nextInt(); while (idnum!=-1) { sc.nextLine(); // skip \n System.out.println("Enter employee's name: "); // read in user input name = sc.nextLine(); System.out.println("You entered: " + idnum + " " + name); System.out.println("Enter employee's hours and rate: "); // read in user input hours = sc.nextDouble(); rate = sc.nextDouble(); System.out.println("you entered hours: " + hours + " rate: " + rate); // if hours>40 give 1.5*rate for all overtime hours if (hours > 40) { grossPay = (hours-40)*rate*1.5+40*rate; } else { grossPay = rate * hours; } // rule for taxes, 25% off if salary is > 1000 // 15% off otherwise double taxes; if (grossPay >= 1000) { taxes = .25*grossPay; } else { taxes = .15*grossPay; } netPay = grossPay - taxes; System.out.println(idnum + " " + name + " grossPay: " + grossPay + " netPay: " + netPay); numEmployees++; totalPay+=grossPay; // totalPay = totalPay + grossPay; // structured read loop System.out.println("Enter id number, -1 to finish"); idnum = sc.nextInt(); } // end while loop // fall out of while loop, print count and sum System.out.println("We processed " + numEmployees + " employees." + " Total pay is " + totalPay); sc.close(); } } /*** Lab */