307,387 views
44 votes
44 votes
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 the AcmePay 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
Hourly pay rate
Regular pay
Overtime pay
Retirement deduction, if any
Net pay.

An example of the program is shown below:

Please enter shift - 1, 2, or 3
2
Please enter hours worked
9
Do you want to participate in the retirement plan?
Enter 1 for Yes and 2 for No.
1

Hours worked is 9.0
Hourly pay rate is 18.5
Regular pay is 166.5
Overtime pay is 0.0
Retirement deduction is 4.995
Net pay is....................161.505

User Pedram
by
3.0k points

1 Answer

18 votes
18 votes

import java.util.*;

public class AcmePay {

public static void main(String[] args) throws Exception {

double regularPay = 0, overPay = 0;

double wage1 = 17, wage2 = 18.50, wage3 = 22, time = 0;

double overworkMethod = 1.5, retirementDeduction = 0;

Scanner input = new Scanner (System.in);

System.out.println("Please enter shift - 1, 2, or 3");

int shift = input.nextInt();

System.out.println("Please enter hours worked");

double hoursWorked = input.nextDouble();

//regular pay

if (shift == 1 && hoursWorked > 40){

regularPay = (40 * wage1);

}

else if (shift == 2 && hoursWorked > 40){

regularPay = (40 * wage2);

}

else if (shift == 3 && hoursWorked > 40){

regularPay = (40 * wage3);

}

else if (shift == 1 && hoursWorked < 40){

regularPay = wage1 * hoursWorked;

}

else if (shift == 2 && hoursWorked < 40){

regularPay = wage2 * hoursWorked;

}

else if (shift == 2 && hoursWorked < 40){

regularPay = wage2 * hoursWorked;

}

// OVER PAY

if (hoursWorked > 40 && shift == 1){

overPay = (hoursWorked - 40) * (wage1 * 1.5);

}

else if (hoursWorked > 40 && shift == 2) {

overPay = (hoursWorked - 40) * (wage2 * 1.5);

}

else if (hoursWorked > 40 && shift == 3){

overPay = (hoursWorked - 40) * (wage3 * 1.5);

}

else if (hoursWorked < 40 && (shift == 1 || shift == 2 || shift == 3)){

overPay = 0.0;

}

//NET PAY

double netPay = 0;

if (shift == 1) {

netPay = overPay + regularPay;

}

else if ((shift == 2 || shift == 3) && retirementDeduction == 0.0){

netPay = overPay + regularPay;

}

else if ((shift == 2 || shift == 3) && retirementDeduction > 0.0){

netPay = ((overPay + regularPay) - retirementDeduction);

}

//retirement deduction

if (shift == 2 || shift == 3) {

System.out.println("Do you want to participate in the retirement plan?\\ Enter 1 for Yes and 2 for No.");

int chooseRetirement = input.nextInt();

if (chooseRetirement == 1 && shift == 2) {

retirementDeduction = (netPay * 0.03);

}

else if (chooseRetirement == 1 && shift == 3){

retirementDeduction = (netPay * 0.03);

}

}

System.out.println("Hours worked is " + hoursWorked);

if (shift == 1){

System.out.println("Hourly pay rate is " +wage1);

}

else if (shift == 2){

System.out.println("Hourly pay rate is " +wage2);

}

else {

System.out.println("Hourly pay rate is " +wage3);

}

System.out.println("Regular pay is " + regularPay);

System.out.println("Overtime pay is " + overPay);

System.out.println("Retirement deduction is " + retirementDeduction);

System.out.println("Net pay is...................." + (netPay - retirementDeduction));

}

}

User Ted Shaw
by
2.8k points