Question

Hourly workers are paid at their regular pay rate for their first 40 hours worked each...

Hourly workers are paid at their regular pay rate for their first 40 hours worked each week. Any hours beyond that are considered overtime, and they get paid "time-and-a-half" for those hours (1-1/2 times their regular pay rate).

For example, if a worker normally makes $12.00 per hour and has worked 45 hours in the past week, the pay is computed as follows: 40 times $12 for the "regular" hours is $480. The extra 5 hours is overtime and is paid at $18 per hour ($12 times 1.5 is $18). The "overtime pay" is 5 times $18, which is $90. Total pay would then be $480 + 90, which is $570.

Step1: Write a java program in Eclipse that will ask the user for a worker's pay rate and the number of hours worked this week. Print on the screen the number of overtime hours, how much regular pay the worker should receive, how much overtime pay, and the total pay for this week.

Step 2: Add comment statements from beginning to end.

Step3: Compile and test your program. Make sure it works properly and gives the correct answers for different inputs. TAKE SCREENSHOT OF 2 different values of OUTPUT

Your program should have

  1. Do while loop,           2. Atleast one method              3. Output with rounded values.

Here's a sample run of the program:

What is the pay rate? 9.50

How many hours worked this week? 42

You have worked 2 hours of overtime,

Regular pay is $380.00

Overtime pay is $28.50

Total pay is $408.50

Do you want to calculate for another set of hours? Press Y or N Y

What is the pay rate? 12.50

How many hours worked this week? 32

You have worked 0 hours of overtime

Regular pay is $400.00

Overtime pay is $0.00

Total pay is $400.00

Do you want to calculate for another set of hours? Press Y or N n

Homework Answers

Answer #1

As per your requiremetnt, here is the Java code:

Rawcode:

//importing required packages
import java.util.*;
import java.math.RoundingMode;
import java.text.DecimalFormat;
//creating a class
public class HourlyPayRate {
   //main function
   public static void main(String[] args)
   {
       //declaring variables
       double payRate;
       int noOfHours;
       char choice;
       //creating a scanner class
       Scanner input = new Scanner(System.in);
       //starting of so while loop this will run till user enters y or Y
       do
       {
           //asking user to enter pay rate
           System.out.printf("What is the pay rate? ");
           //reading input from user
           payRate = input.nextDouble();
           //asking user to enter number of hours he worked
           System.out.printf("How many hours worked this week? ");
           //reading input from user
           noOfHours = input.nextInt();
           //calling function to calculate and print the regular pay, overtime pay and total pay
           calculateTotalPayrate(payRate, noOfHours);
           //asking user to enter a character of Y to continue or N to exit the program
           System.out.printf("Do you want to calculate for another set of hours? Press Y or N ");
           //reading a character from user
           choice = input.next().charAt(0);
       }while(choice == 'y' || choice == 'Y');
   }
   //function to calculate and print the regular pay, overtime pay and total pay
   public static void calculateTotalPayrate(double payRate, double noOfHours) {
       //declaring variables
       double regularPay, overtimePay, totalPay;
       //checking if number of hours is less than 40
       if(noOfHours <= 40) {
           //if it is less than 40 then calculating regular pay that is payrate times of number of hours
           regularPay = (double) noOfHours * payRate;
           //so there is no overtime pay then set it to 0
           overtimePay = 0.00;
       }
       //if number of hours is greater than 40
       else {
           //then calculating regular pay for first 40 hours
           regularPay = (double) (40 * payRate);
           //and calculating the overtime pay for remaining hours
           overtimePay = (double) ((noOfHours - 40) * (payRate * 1.5));
       }
       //calculating total pay by adding regular pay and overtime pay
       totalPay = regularPay + overtimePay;
       //creating decimal format object to print upto 2 decimal places
       DecimalFormat df = new DecimalFormat("#.##");
       //rounding the last of digit of decimal point
       df.setRoundingMode(RoundingMode.CEILING);
       //printing regular pay
       System.out.println("Regular pay is $" + df.format(regularPay));
       //printing overtime pay
       System.out.println("Overtime pay is $" + df.format(overtimePay));
       //printing total pay
       System.out.println("Total pay is $" + df.format(totalPay));
   }
}
Here is the screenshot of source code:

Here is the screenshot of output:

Hope this helps you. Please feel free to ask if you still have any queries.

Do upvote. Thank you !

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Coding Federal law requires that hourly employees be paid “time and a half” for all...
Python Coding Federal law requires that hourly employees be paid “time and a half” for all work above 40 hours per week. Write a program that prompts the user to enter their hours worked and hourly wage (e.g. $20.00/hr) and then computes and prints their pay. The program should test the number of hours worked to determine if any overtime pay is due. As an example for regular pay (no overtime) suppose that a worker makes $10/hr and works 40...
Jack Kenston works a 40-hour week with overtime paid at 1.5 times his regular rate of...
Jack Kenston works a 40-hour week with overtime paid at 1.5 times his regular rate of pay of $14.88. This week he worked 42 hours, which resulted in a gross pay of __________. Harry is paid a semimonthly salary of $1,900.00. Overtime is paid for hours beyond 40 in each workweek. One week, Harry works 5.5 hours overtime. Harry’s pay for this semimonthly pay period is _____. Samual receives an annual $29,700 base salary for working the territory in Arizona....
Description Write a program that reads in the name, hourly rate and number of hours worked...
Description Write a program that reads in the name, hourly rate and number of hours worked for 5 people. Print the name of each person, the number of hours worked, their weekly pay based on the number of hours they worked and how much they owe in taxes. Assume that taxes take 20% of the paycheck. Don’t forget to take the taxes out of the pay check. If they work more than 40 hours they get overtime. The hourly rate...
An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular...
An employee’s total weekly pay equals the hourly wage multiplied by the total number of regular hours plus any. Overtime pay equals the total overtime hours multiplied by 1.5 times the hourly wage. Write a program that takes as input the hourly wage. Total regular hours. And total overtime hours and displays an employee’s total weekly pay.
Example 2-19 Matt Leonard earns $739.20 a week with fluctuating workweek hours. If he worked 48...
Example 2-19 Matt Leonard earns $739.20 a week with fluctuating workweek hours. If he worked 48 hours in one week, his gross pay would be calculated as follows: $739.20 ÷ 48 hours = $15.40 regular rate $15.40 × 0.5 = $7.70 extra half pay rate 8 hours O.T. × $7.70 = $61.60 extra pay $739.20 + $61.60 = $800.80 weekly gross pay Example 2-21 The agreement between John Kalas and his employer provides for a pay rate of $14 per...
Suppose an employer wants a worker to work overtime. At the regular wage rate, the optimal...
Suppose an employer wants a worker to work overtime. At the regular wage rate, the optimal choice of hours of work for a worker is exactly the full-time work. Show the optimal choice in an income-leisure diagram, and show how the worker's choice would change for (a) the double wage rate for every hour worked; (b) the double wage rate for overtime hours only (i.e., up to full time, the worker is paid w, and for every hour above the...
Engineered cost variances Fred’s Freight employs three drivers who are paid $26 per hour for regular...
Engineered cost variances Fred’s Freight employs three drivers who are paid $26 per hour for regular time and $39 for overtime. A single pickup and delivery requires, on average, one hour of driver time. Drivers are paid for a 40-hour week because they must be on call all day. One driver stands by for after-hour deliveries. Analyze the labor cost variances for one week in which the company made 106 daytime deliveries and 10 after-hour deliveries. The payroll for drivers...
Paul Curcio earns $7.65 per hour for regular time up to 40 hours, time-and-a-half for overtime,...
Paul Curcio earns $7.65 per hour for regular time up to 40 hours, time-and-a-half for overtime, and double time for working on holidays. Find his gross pay (in $) if he worked 6 holiday hours for a total of 58 hours Monday through Saturday.
At Gleeson Brewing Company, office workers are employed for a 40-hour workweek; each individual's salary is...
At Gleeson Brewing Company, office workers are employed for a 40-hour workweek; each individual's salary is quote on either an annual or a monthly basis. Given on the form below are the current annual and monthly salary rates for five office workers for the week ended December 14, 2018 (50th payday of the year). In addition, with this pay, these employees are paid their sliding-scale annual bonuses. The bonuses are listed on the register. For each worker, compute the following....
K. Mello Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll...
K. Mello Company has three employees-a consultant, a computer programmer, and an administrator. The following payroll information is available for each employee: Consultant Computer Programmer Administrator Regular earnings rate $2,510 per week $28 per hour $50 per hour Overtime earnings rate Not applicable 2 times hourly rate 1.5 times hourly rate Federal income tax withheld $920 $240 $495 For hourly employees, overtime is paid for hours worked in excess of 40 hours per week. For the current pay period, the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT