Employees Year of Service Salary Bonus in Java
The current year and the year in which the employee joined the organization are entered through the keyboard. If the number of years for which the employee has served the organization is greater than 3 then a bonus of Rs. 2500/- is given to the employee. If the years of service are not greater than 3, then the program should do nothing
- The program starts by importing the Scanner class from the java.util package, which allows the user to enter input from the console.
- Next, the main method is defined, which is the entry point of the program. Inside the main method, a new Scanner object is created to read input from the console. Then, the user is prompted to enter the current year using the System.out.print statement. The input is read using the nextInt method of the Scanner class and stored in an integer variable current_year.
- The user is then prompted to enter the year of joining using the System.out.print statement. The input is read using the nextInt method of the Scanner class and stored in an integer variable join_year.
- Next, the program calculates the difference between the current year and the year of joining using the formula:
- Difference = Current Year - Year of Joining
- If the difference is greater than 3, the employee is eligible for a bonus of Rs. 2500. If the difference is 3 or less, the employee is not eligible for a bonus.
- After determining whether the employee is eligible for a bonus or not, the program displays the result to the console using the System.out.println statement.
Source Code
import java.util.Scanner;
class Employee_Bonus
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
System.out.print("Enter the Current Year : ");
int current_year = input.nextInt();
System.out.print("Enter the Year of Joining : ");
int join_year = input.nextInt();
int diff = current_year - join_year;
if(diff>3)
{
System.out.println("Bonus of Rs : 2500 /-");
}
else
{
System.out.println("No Bonus");
}
}
}
Output
Enter the Current Year : 2022
Enter the Year of Joining : 2014
Bonus of Rs : 2500 /-