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

Create a program to compute a worker\'s daily salary in java. input: hour_rate,

ID: 662799 • Letter: C

Question

Create a program to compute a worker's daily salary in java.

      input: hour_rate, number_of_hours

   output: salary = hour_rate * number_of_hours

Modify the program to compute a worker's daily salary based on the following table:

   --------------------------------------

   | $7.00/hr | The first 8 hours |

   --------------------------------------

   | $9.00 /hr | After 8 hours |

   --------------------------------------

   For example, if a worker works 10 hours, then her/his salary is

       $7.00/hr * 8 hrs + $9.00/hr * (10 - 8) hrs

   Note: The number 7.00 is read from keyboard. 9.00 is fixed.

   Modify the program to compute N worker's daily salary.

   The number N is an input to this program.

Explanation / Answer

/**The java program that prompts the number of workers
* and asks to enter number of hours and pay rate of the worker
* then calculate the salary for each employee for N workers
* and display the salary as per the given pay rates in the program and display the total salary paid to workers.
* */
//WorkerDailySalary.java
import java.util.Scanner;
public class WorkerDailySalary
{
   public static void main(String[] args)
   {
       //create an instance of Scanner class object
       Scanner scanner=new Scanner(System.in);

       //create over time pay rate as 9 $ per hour       
       final int OVER_TIME_PAYRATE=9;

       //declare variables
       int number_of_hours; // number of hours
       double hour_rate; //hours rate  
       double salary; //to store salary
       double totalPay=0; //total salary pay
       int N; //number of workers


       System.out.println("Enter number of workers ");
       //prompt for number of workers
       N=scanner.nextInt();

       //set worker to zero
       int worker=0;
      
       //run while loop that prompts for N workers
       while(worker<N)
       {
          
           //prompt for hours and rate
           System.out.println("Enter number of hours");
           number_of_hours=scanner.nextInt();

           //enter 7 $ as normal pary rate
           System.out.println("Enter hour rate (Enter 7$ from keyboard))");
           hour_rate=scanner.nextDouble();

           //if number of hours are greater than 8
           //then calculate the salary with over time pay rate
           if(number_of_hours>8)
               salary = hour_rate *8+(number_of_hours-8)*OVER_TIME_PAYRATE;
           //othrewise calculate normal pay rate 7 $ for hour
           else
               salary = hour_rate *number_of_hours;

           //display the worker salary who works less than 8 hours
           if(number_of_hours<=8)
           {
               System.out.println("Number of Hours : "+number_of_hours);
               System.out.println("Pay Rate for first 8 hours $: "+hour_rate);
               System.out.println("Salary : $"+salary);
           }
           //display the worker salary who works greater than 8 hours
           else
           {
               System.out.println("Number of Hours : "+number_of_hours);
               System.out.println("Pay Rate for first 8 hours $: "+hour_rate);
               System.out.println("Pay Rate after 8 hours : $"+OVER_TIME_PAYRATE);
               System.out.println("Salary : $"+salary);
           }
          
           //add salary to the total pay
           totalPay=totalPay+salary;
          
           //increment worker by one
           worker=worker+1;

       }//end of while loop
      
       System.out.println("Total salary paid to the workers : $"+totalPay);

   }//end of main method
  
}//end of the class

-------------------------------------------------------------------------------------------------------------------------------------------------

Sample output:

Enter number of workers
2
Enter number of hours
10
Enter hour rate (Enter 7$ from keyboard))
7
Number of Hours : 10
Pay Rate for first 8 hours $: 7.0
Pay Rate after 8 hours : $9
Salary : $74.0
Enter number of hours
20
Enter hour rate (Enter 7$ from keyboard))
7
Number of Hours : 20
Pay Rate for first 8 hours $: 7.0
Pay Rate after 8 hours : $9
Salary : $164.0
Total salary paid to the workers : $238.0

Hope this helps you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote