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.
This is the program I have written so far:
import java.util.Scanner;
public class AcmePay
{
public static void print(double h, int s, double rate, double regularPay, double overtime, double total, int r, double gross)
{
System.out.print("\n");
System.out.println("****************************** *******");
System.out.println("****************************** *******");
System.out.println("Hours worked : "+ h);
System.out.println("Shift: " + s);
System.out.println("Hourly Pay Rate : $" + rate);
System.out.println("Regular Pay : $" + regularPay);
System.out.println("Overtime Pay : $" + overtime);
System.out.println("Total of regular and overTime pay : $" + total);
if(r == 1)
{
System.out.println("Retirment deduction " + (total - gross));
}
System.out.println("Net Pay: $"+ gross);
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print("Hours worked: ");
double hour = s.nextDouble();
System.out.print("Shift: ");
int shift = s.nextInt();
double pay;
double overpay = 0;
double totalPay ;
double hourRate;
int retire;
double netPay = 0;
if(shift == 1)
{
pay = 17 * hour;
if(hour>40)
{
overpay = ((hour - 40) * 25.5);
}
totalPay = pay + overpay;
hourRate = 17;
print(hour,shift,hourRate,pay,overpay,totalPay,0,t otalPay);
}
else if(shift ==2 || shift == 3)
{
System.out.print("Did you elect for retirement: ");
retire = s.nextInt();
if(shift == 2)
{
pay = (18.50 * hour);
if(hour>40)
{
overpay = ((hour - 40) * 27.75);
}
totalPay = pay + overpay;
if(retire==1)
{
netPay = totalPay - ((totalPay * 3)/100);
}
else{
netPay = totalPay;
}
hourRate = 18.50;
print(hour,shift,hourRate,pay,overpay,totalPay,ret ire,netPay);
}
else if(shift ==3)
{
pay = 22 * hour;
if(hour>40)
{
overpay = ((hour - 40) * 33);
}
totalPay = pay + overpay;
if(retire == 1)
{
netPay = totalPay - ((totalPay * 3)/100);
}
else
{
netPay = totalPay;
}
hourRate = 22;
print(hour,shift,hourRate,pay,overpay,totalPay,ret ire,netPay);
}
}
else
{
System.out.println("Invalid shift");
}
}
}