Simple employee salary calculator

 In this example consider that every employee is getting $37.50 per hour and the standard hours per week is 40 hours/week. If any employee works more than 40 hours per week then he/she should be earning $2.50 additional per extra hour worked.

import java.util.Scanner;

public class SalaryCalculator {

    public static void main(String[] args) {

        System.out.print("Enter number of hours worked: ");
        Scanner in = new Scanner(System.in);
        double totalHoursWorked = in.nextInt();
        double standardWage = 37.50;
        int standardHours = 40;
        double totalWage;
        double overtimeBonus = 2.50;

        if (totalHoursWorked > 40)
            totalWage = (standardWage * totalHoursWorked)
                        + (totalHoursWorked - standardHours) * overtimeBonus;
        else if (totalHoursWorked < 40)
            totalWage = standardWage * totalHoursWorked;
        else
            totalWage = standardWage * standardHours;

        System.out.println("Your total salary of the week is: " + totalWage);
    }
}


Output:

Enter number of hours worked: 30
Your total salary of the week is: 1125.0

10 comments:

  1. It is indeed a very useful program (calculator) for calculating the wages of the employees. However, in real life scenarios the company changes policies very often and the factors of calculating the salary of the staff could be very complex.

    Payroll Providers Guelph

    ReplyDelete
  2. In a company named Micky software solution, many part-time employees are working for a pay of Rs. 100 per hour. Write a program to calculate the total amount an employee earns in a year by working part time. Consider employees should work all day in the year and year has 365 days.

    Note : The hour should be a positive value less than or equal to 24, if fails display "Unable to calculate the earnings"

    Sample Input 1:
    Enter no of hours worked in a day:3

    Sample Output 1:
    Total income in a year:109500

    Sample Input 2:
    Enter no of hours worked in a day:0

    Sample Output 2:
    Total income in a year:0

    Sample Input 3:

    Enter no of hours worked in a day:-5

    Sample Output 3:
    Unable to calculate the earnings

    ReplyDelete
    Replies
    1. can anybody answer this question? it is always giving me error check for positive value

      Delete
    2. it is always giving me error Check for Invalid input?

      Delete
  3. add if(earnings>=0) condition

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. The salary calculator is a great and fast way compared to manual...ga hourly paycheck calculator

    ReplyDelete