Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

3 of 4 - + Automatic Zoom: Problem #04: Compute a Paycheck (5 points) Write a pr

ID: 3688700 • Letter: 3

Question

3 of 4 - + Automatic Zoom: Problem #04: Compute a Paycheck (5 points) Write a program that ask the user to enter their hourly wage and the number of hours they worked in the past week. NOTE: The number of hours worked could be fractional as in 3.5 hours. Also, any overtime worked (overtime is any hours worked above 40 hours) is paid at 150% of the regular hourly wage. Compute and display the paycheck for the employee using the format given in the sample output below. NOTE: Some combinations of input will result with no overtime pay, while others will have overtime pay. Test your program with all combinations of input. Input Validation: Do not accept negative values for any of the inputs. Sample Output: What is your hourly wage: 10.25 How many hours did you work this week? 50.5 Hourly Wage: $10.25 Hours Worked: 50.5 Regular Pay: $410.0 8 9 0 RTYU 7 FGH JK ENTER -

Explanation / Answer

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
   public static void main (String[] args) throws java.lang.Exception
   {
       Scanner in = new Scanner(System.in);
       System.out.println("What is your hourly wage?: ");
       float wage = in.nextFloat();
       while(wage<0)
       {
               System.out.println("What is your hourly wage?: ");
               wage = in.nextFloat();
       }
       System.out.println("How many hours did you work this week?: ");
       float hr = in.nextFloat();
       while(hr<0)
       {
           System.out.println("How many hours did you work this week?: ");
           hr = in.nextFloat();
       }
      
       System.out.println("Hourly wage: $"+wage);
       System.out.println("Hours worked: $"+hr);
      
       float regular_pay, overtime_pay;
      
      
       if(hr>40)
       {
           overtime_pay = wage*1.5f*(hr-40.0f);
           regular_pay = wage*40.0f;
       }else
           {
               overtime_pay = 0;
               regular_pay = wage*hr;
           }
      
       System.out.println("Regular Pay: $"+regular_pay);
       System.out.println("Overtime Pay: $"+overtime_pay);
       System.out.println("Total Pay: $"+(regular_pay+overtime_pay));
      
      
      
   }
}