Java Program to Calculate Salary of an Employee

In the previous article, we have seen Java Program to Calculate Total Amount from Number of Notes

In this article we are going to see how to calculate salary of an employee or Employee Salary Program In Java using java programming language. Along with that we include all details relevant to the employee salary calculation program in java, likewise java program to calculate gross salary and net salary, salary program in java, java program to calculate net salary of an employee, there are types of salary programs in java. They are Basic salary program in java. Implementation a java program to calculate Gross salary and Net salary. Employee Salary Calculation Program In Java Accenture etc…

Java Program to Find Salary of an Employee

Java program to calculate salary of an employee is a combination of multiple things like the basic salary, daily allowance(DA), provident fund(PF), house rent allowance(HRA) etc.

Primarily, DA and all the allowances are calculated based on the basic salary only.

For example let’s consider the following break up for the salary

  • DA = 7%
  • HRA = 10%
  • PF = 8%

Let’s see different ways to calculate salary of an employee.

Method-1: Java Program to Calculate Salary of an Employee By Using Static Input Value

Approach:

  • Initialize a double variable basicSalary to 15000.
  • Declare variables to store the allowances.
  • Now calculate the allowances of the employee according to percentage given above.
  • Now add up all the allowances and basic salary to give the final salary.

Program:

public class Main
{
    public static void main(String[] args)
    {
        double basicSalary, hra, da, PF, netSalary;
        //basic salary of employee declared
        basicSalary = 15000;
        
        //calculating HRA, DA and PF
        hra = basicSalary * 0.1;
        da = basicSalary * 0.07;
        PF = basicSalary * 0.08;

        //Calculating net salary by adding basicSalary, hra, da and deducting PF from that
        netSalary = basicSalary + hra + da - PF;

        System.out.println("The Basic salary is:" + basicSalary);
        System.out.println("The HRA is:" + hra);
        System.out.println("The DA is:" + da);
        System.out.println("The PF is:" + PF);
        System.out.println("The net salary is:" + netSalary);
    }

}
Output:

The Basic salary is:15000.0
The HRA is:1500.0
The DA is:1050.0
The PF is:1200.0
The net salary is:16350.0

Method-2: Java Program to Calculate Salary of an Employee By Using User Input

Approach:

  • Create Scanner class object.
  • Declare variables to store the allowances.
  • Take user input for basic salary.
  • Now add up all the allowances and basic salary to give the final salary.

Program:

import java.util.Scanner;

public class Main 
{
    public static void main(String[] args) 
    {
        double basicSalary, hra, da, PF, netSalary;
        
        //Scanner class object created
        Scanner sc = new Scanner(System.in);
        //taking user input of basic salary
        System.out.println("Enter basic salary:");
        basicSalary = sc.nextDouble();

        //calculating HRA, DA and PF
        hra = basicSalary * 0.1;
        da = basicSalary * 0.07;
        PF = basicSalary * 0.08;

        //Calculating net salary by adding basicSalary, hra, da and deducting PF from that
        netSalary = basicSalary + hra + da - PF;

        System.out.println("The Basic salary is:" + basicSalary);
        System.out.println("The HRA is:" + hra);
        System.out.println("The DA is:" + da);
        System.out.println("The PF is:" + PF);
        System.out.println("The net salary is:" + netSalary);
    }

}
Output:

Enter basic salary:
15000
The Basic salary is:15000.0
The HRA is:1500.0
The DA is:1050.0
The PF is:1200.0
The net salary is:16350.0

Explore complete java concepts from the Java programming examples and get ready to become a good programmer and crack the java software developer interview with ease.

Recommended Reading On: Java Program to Find the Amount of Tax to be Deducted From the Salary of an Employee

After observing the above employee salary based program in java you can practice some of the problems given below.

  1. Write A Program To Calculate The Gross Salary Of An Employee In Java
  2. Write A Program To Calculate Total Salary Of An Employee In Java
  3. Write A Java Program To Input Basic Salary Of An Employee And Calculate Its Gross Salary
  4. Write A Java Program To Find The Gross Salary And Net Salary Of An Employee Using Constructor
  5. Calculate Salary In Java Code
  6. Calculate Salary Program In Java
  7. Calculate Salary In Java
  8. Gross Salary Java Program
  9. Total Salary Program In Java

Related Java Programs: