Calculate Weekly Salary and Overtime Pay in Java

The following Java program application calculates the Weekly Salary of an employee. The program determines an employee’s weekly wages. If the hours worked exceed 40, then wages include overtime payment. . I will be using the JCreator IDE in developing the program. To start in this tutorial, first open the JCreator IDE, click new and paste the following code.
  1. import java.util.*;
  2.  
  3. public class WeeklyWages
  4. {
  5.  
  6. static Scanner console = new Scanner(System.in);
  7.  
  8. public static void main(String[] args)
  9. {
  10.  
  11. double wages, rate, hours;
  12.  
  13. System.out.print("Enter the working hours:");
  14. hours = console.nextDouble();
  15. System.out.println();
  16.  
  17. System.out.print("Enter the pay rate:");
  18. rate = console.nextDouble();
  19. System.out.println();
  20.  
  21.  
  22. if (hours > 40.0)
  23. wages = 40.0 * rate +
  24. 1.5 * rate * (hours - 40.0);
  25.  
  26. else
  27. wages = hours * rate;
  28.  
  29. System.out.printf("The wages are $%.2f %n",
  30. wages);
  31.  
  32. System.out.println();
  33.  
  34. }
  35. }
Sample run #1:
  1. Enter the working hours:40
  2.  
  3. Enter the pay rate:12
  4.  
  5. The wages are $480.00
Sample run #2:
  1. Enter the working hours:45
  2.  
  3. Enter the pay rate:100
  4.  
  5. The wages are $4750.00
The program works as follows: The statement
  1. System.out.print("Enter the working hours:");
  2. hours = console.nextDouble();
  3. System.out.println();
prompts the user to input the number of hours worked. The statement
  1. System.out.print("Enter the pay rate:");
  2. rate = console.nextDouble();
  3. System.out.println();
prompts the user to enter the pay rate. The statement
  1. if (hours > 40.0)
  2. wages = 40.0 * rate +
  3. 1.5 * rate * (hours - 40.0);
checks whether the value of the variable hours is greater than 40.0 If hours are greater than 40.0, then the wages are calculated, which also includes overtime payment, the wages are calculated by the statement  wages = hours * rate;

Comments

Submitted byAbdulmalik ibrahin (not verified)on Tue, 06/19/2018 - 03:48

Good class for biginner

Add new comment