Q:

Java program to calculate the gratuity of an employee

belongs to collection: Java Basic Programs

0

Java program to calculate the gratuity of an employee

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

In this program, we will read the basic salary and dearness allowance of an employee from the user and calculate the gratuity of the employee.

Program/Source Code:

The source code to calculate the gratuity of an employee is given below. The given program is compiled and executed successfully.

// Java program to calculate the 
// gratuity of an employee

import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner X = new Scanner(System.in);

    float basicPay = 0;
    float da = 0;
    int years = 0;

    float gratuity = 0;

    System.out.printf("Enter years of service: ");
    years = X.nextInt();

    if (years < 5) {
      System.out.printf("You are not eligible for gratuity");
      return;
    }

    System.out.printf("Enter basic pay: ");
    basicPay = X.nextFloat();

    System.out.printf("Enter dearness allowance: ");
    da = X.nextFloat();

    gratuity = ((basicPay + da) * 15 / 26) * years;

    System.out.printf("Gratuity amount is: %f\n", gratuity);
  }
}

Output:

Enter years of service: 10
Enter basic pay: 21800
Enter dearness allowance: 2500
Gratuity amount is: 140192.312500

Explanation:

In the above program, we imported the "java.util.Scanner" package to read input from the user. Here we created a public class Main. It contains a static method main().

The main() method is an entry point for the program. Here, we read the basic salary and dearness allowance of an employee from the user and calculated the gratuity amount and printed the result.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to compare float and double values... >>
<< Java program to calculate the employee and employe...