/* 9/16/2019 Problem: given information about two Employees, calculate and print pay */ import java.util.Scanner; /** This is version 1 of Payroll. We added overtime and taxes * (uses if stmt, if-else, conditional operator AND printf for formatted printing) * block SCOPE * don't put identical stmts into if and else */ public class PayrollV1 { /** 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 // prompt the user System.out.println("Enter employee 1's ID number: "); idnum = sc.nextInt(); sc.nextLine(); // skip \n System.out.println("Enter employee 1's name: "); // read in user input name = sc.nextLine(); System.out.println("You entered: " + idnum + " " + name); System.out.println("Enter employee 1'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); // NOW PROCESS EMPLOYEE 2 // prompt the user System.out.println("Enter employee 2's ID number: "); idnum = sc.nextInt(); sc.nextLine(); // skip \n System.out.println("Enter employee 2's name: "); // read in user input name = sc.nextLine(); System.out.println("You entered: " + idnum + " " + name); System.out.println("Enter employee 2'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 // we are using the conditional operator for emp2 // When can we use the conditional? instead of if-else // typically, when you are assigning a value to a var based on a condition // identical to lines 46-51 taxes = (grossPay >= 1000) ? .25*grossPay : .15*grossPay; netPay = grossPay - taxes; System.out.printf("%d %s grossPay: $%,10.2f $%,10.2f\n",idnum,name,grossPay,netPay); sc.close(); } } /*** Lab 5: use if-else, conditional, printf * open celcius2 program and modify as follows: * use if-else-if to print: * hot, cold, comfortable * use conditional operator to set a boolean variable called isCold * print the values of celcius and faranheit with 2 digits after decimal point */