Write a public method that takes two arguments: a double representing the number
ID: 3919332 • Letter: W
Question
Write a public method that takes two arguments: a double representing the number of hours worked and a double representing the hourly pay, and returns a double representing the weekly pay. If the hours are less than or equal to 40, the weekly pay should be hours times hourly pay. If the hours are greater than 40 and less than 80, the weekly pay should be 40 times the hourly pay, plus the hours in excess of 40 times hourly pay times 1.5. If the hours worked are entered as less than zero or greater than 80, print an error message saying "incorrect number of hours entered" and return 0.0;
Explanation / Answer
public double weeklyPay(double hoursWorked ,double hourlyPay)
{
if(hoursWorked <= 40)
return hoursWorked*hourlyPay;
else if(hoursWorked >= 40 && hoursWorked <80)
return 40*hourlyPay+ (hoursWorked-40)*1.5*hourlyPay;
else
{
System.out.println("incorrect number of hours entered");
}
return 0.0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.