By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,906 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

I need help writing a program that shows a pay for 3 shifts with deductions

P: 1
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");
}

}
}
Oct 24 '18 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 785
Please use code tags to format the code so it is easier for us free helpers to read your program.

You mentioned that you need help, but you forgot to mention what problem you have.
So what is your program doing different as it's supposed to do? Where is the error message? Where are you stuck?
Apr 5 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.