Write a program to calculate the salary as per the following table
Gender | Year of Service | Qualifications | Salary |
---|---|---|---|
Male | >= 10 | Post - Graduate | 15000 |
>= 10 | Graduate | 10000 | |
< 10 | Post - Graduate | 10000 | |
< 10 | Graduate | 7000 | |
Female | >= 10 | Post - Graduate | 12000 |
>= 10 | Graduate | 9000 | |
< 10 | Post - Graduate | 10000 | |
< 10 | Graduate | 6000 |
The program starts by importing the Scanner class to take input from the user. It then prompts the user to enter the years of service, gender, and qualification. The program reads in these values using nextInt() and next().charAt(0) methods of the Scanner class and stores them in separate variables.
After this, the program uses if-else statements to determine the salary of the employee based on their gender, years of service, and qualification.
For male employees, if they have been in service for 10 or more years (yos>=10) and have a post-graduate qualification (qual==1), their salary is set to 15000. For other male employees, the salary is set to 10000 if they have been in service for 10 or more years and have a graduate qualification (qual==0), or if they have a post-graduate qualification and have been in service for less than 10 years, or if they are female and have a post-graduate qualification and have been in service for less than 10 years.
For female employees, if they have been in service for 10 or more years and have a post-graduate qualification, their salary is set to 12000. For female employees who have been in service for 10 or more years and have a graduate qualification, the salary is set to 9000. For other female employees who have a graduate qualification and have been in service for less than 10 years, the salary is set to 6000.
Finally, the program outputs the calculated salary using the System.out.println() method.
import java.util.Scanner; class Calculate_Salary { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the Years of Service :"); int yos = input.nextInt(); System.out.print("Enter the Gender f/m :"); char gen = input.next().charAt(0); System.out.print("Enter the Qualification (Graduate(0) , Post-Graduate(1)) :"); int qual = input.nextInt(); int salary = 0; if(gen=='m' && yos>=10 && qual==1) { salary = 15000; } else if( (gen=='m' && yos>=10 && qual==0) || ( gen=='m' && yos<10 && qual==1 ) || ( gen=='f' && yos<10 && qual==1)) { salary = 10000; } else if(gen=='m' && yos<10 && qual==0) { salary = 7000; } else if(gen=='f' && yos>=10 && qual==1) { salary = 12000; } else if(gen=='f' && yos>=10 && qual==0) { salary = 9000; } else if(gen=='f' && yos<10 && qual==0) { salary = 6000; } System.out.println("Salary : " + salary); } }
Enter the Years of Service :5 Enter the Gender f/m :m Enter the Qualification (Graduate(0) , Post-Graduate(1)) :1 Salary : 10000
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions