Thursday, February 29, 2024

Write a Java program to calculate the gross salary of an employee, if basic salary of that employee is greater or equal to 20000 and year's of service is equal or greater than 5 years bonus will be 2000 else1000, TA =10%, DA= 20% and HRA=5% of salary.

import java.util.Scanner;

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

        System.out.print("Enter the basic salary of the employee: ");
        double basicSalary = scanner.nextDouble();

        System.out.print("Enter the years of service of the employee: ");
        int yearsOfService = scanner.nextInt();

        double bonus = (basicSalary >= 20000 && yearsOfService >= 5) ? 2000 : 1000;
        double ta = 0.10 * basicSalary;
        double da = 0.20 * basicSalary;
        double hra = 0.05 * basicSalary;

        double grossSalary = basicSalary + ta + da + hra + bonus;

        System.out.println("Gross Salary of the employee: " + grossSalary);
    }
}

No comments:

Post a Comment

📚 Other Stream Classes in Java जावा में अन्य स्ट्रीम क्लासेस

In Java, apart from basic byte and character streams, there are several specialized stream classes that provide advanced input-output operat...