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

Java program to implement file input stream class to read binary data from image file.

import java.io.FileInputStream; import java.io.IOException; public class ReadImageFile {     public static void main(String[] args) {       ...