Answer:
Program file
filename: AcmePay.java
import java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
double[] shiftPay = { 17, 18.50, 22 };
double hourlyPayRate = 0, regularPay = 0, overTimeHours = 0, overTimePay = 0, retirementDeduction = 0,
netPay = 0;
System.out.println("*** Employee Pay ***");
// scanner object to read data
Scanner scan = new Scanner(System.in);
// read the number of hours worked from user
System.out.print("Enter the number of hours worked: ");
double numHours = scan.nextDouble();
// read the shift
System.out.print("Enter the shift (1 - 3): ");
int shift = scan.nextInt();
hourlyPayRate = shiftPay[shift];
// calculate regulaPay
regularPay = numHours * hourlyPayRate;
if (numHours > 40) {
overTimeHours = numHours - 40;
overTimePay = overTimeHours * (hourlyPayRate * 1.5);
}
// calculate grossPay
double grossPay = regularPay + overTimePay;
// check for availability of retirement plan
if (shift == 2 || shift == 3) {
System.out.print("Did the worker elected for retirement (1 for yes, 2 for no): ");
int chooseRetirement = scan.nextInt();
if (chooseRetirement == 1) {
// calculate retirement bonus
retirementDeduction = (grossPay * 0.03);
}
}
// calculate netPay
netPay = grossPay - retirementDeduction;
// print the information to stdout
System.out.println("Hours worked: " + numHours);
System.out.println("Shift: " + shift);
System.out.println("Hourly Pay rate: " + hourlyPayRate);
System.out.println("Regular Pay: " + regularPay);
System.out.println("Overtime hours: " + overTimeHours);
System.out.println("Overtime pay: " + overTimePay);
System.out.println("Total of regular and overtime pay (Gross pay): " + grossPay);
System.out.println("Retirement deduction, if any: " + retirementDeduction);
System.out.println("Net pay: " + netPay);
// close scanner object
scan.close();
}
}
Explanation: