Java Program to Calculate the Gratuity of an Employee

You are currently viewing Java Program to Calculate the Gratuity of an Employee

Java program to calculate the gratuity of an employee

// 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

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply