Write a program that prompts the user for hours worked, shift, and, if the shift is 2 or 3, whether the worker elects the retirement (1 for yes, 2 for no). Display: Hours worked Shift Hourly pay rate Regular pay Overtime pay Total of regular and overtime pay Retirement deduction, if any Net pay.
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Acme Parts runs a small factory and employs workers who are paid one of three hourly rates depending on their shift: first shift, $17 per hour; second shift, $18.50 per hour; third shift, $22 per hour. Each factory worker might work any number of hours per week; any hours greater than 40 are paid at one and one-half times the usual rate. In addition, second- and third-shift workers can elect to participate in the retirement plan for which 3% of the worker’s gross pay is deducted from the paychecks.
Write a program that prompts the user for hours worked, shift, and, if the shift is 2 or 3, whether the worker elects the retirement (1 for yes, 2 for no). Display:
- Hours worked
- Shift
- Hourly pay rate
- Regular pay
- Overtime pay
- Total of regular and overtime pay
- Retirement deduction, if any
- Net pay.
What I got so far -
import java.util.*;public class AcmePay{public static void main(String[] args) throws Exception {final double SHIFT1_PAY = 17.00;final double SHIFT2_PAY = 18.50;final double SHIFT3_PAY = 22.00;final double RET_RATE = 0.03;final int FULLWEEK = 40;
Scanner input = new Scanner(System.in);
//prompt shiftSystem.out.println("Please enter shift - 1, 2, or 3");shift = input.nextInt();
//prompt hoursWorkedSystem.out.println("Please enter hours worked");hoursWorked = input.nextDouble();
switch (shift){case 1:payRate = SHIFT1_PAY;break;case 2:payRate = SHIFT2_PAY;break;case 3:break;payRate = SHIFT3_PAY;default:payRate = 0;}
if (hoursWorked > FULLWEEK) //FULLWEEK = 40{regularPay = FULLWEEK * payRate;overtimePay = (hoursWorked - FULLWEEK) * OT_RATE * payRate;}else{regularPay = hoursWorked * payRate;overtimePay = 0.0;}
totalPay = regularPay + overtimePay;
retDeduction = 0;if(shift == 2 || shift == 3){System.out.println("Do you want to participate in the retirement plan?\n" +"Enter 1 for Yes and 2 for No.");
retOption = input.nextInt();if (retOption == 1)retDeduction = totalPay * RET_RATE;}
netPay = totalPay - retDeduction;}}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images