Employee Salary Code - PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

2 public class Employee {

4 // Fill the code

5 private String employeeName;

6 private int employeeId;

7 private int incrementPercentage;

8 private double salary;

10 public void setEmployeeId(int employeeId){

11 this.employeeId=employeeId;

12 }

13 public int getEmployeeId(){

14 return employeeId;

15 }

16 public void setEmployeeName(String employeeName){

17 this.employeeName=employeeName;

18 }

19 public String getEmployeeName(){

20 return employeeName;

21 }

22 public void setSalary(double salary){

23 this.salary=salary;

24 }

25 public double getSalary(){

26 return salary;

27 }

28 public void setIncrementPercentage(int incrementPercentage){

29 this.incrementPercentage=incrementPercentage;

30 }

31 public int getIncrementPercentage(){

32 return incrementPercentage;
33 }

34 public Employee(int employeeId,String employeeName,double salary){

35 this.employeeId=employeeId;

36 this.employeeName=employeeName;

37 this.salary=salary;

38 }

39 public void findIncrementPercentage(int yearsOfExperience){

40 //Calculate the incremented salay of the employee

41 if(yearsOfExperience>=1&&yearsOfExperience<=5){

42 incrementPercentage=15;

43 }

44 else if(yearsOfExperience>=6&&yearsOfExperience<=10){

45 incrementPercentage=30;

46 }

47 else if(yearsOfExperience>=11&&yearsOfExperience<=15){

48 incrementPercentage=45;

49 }

50 }

51 public double calculateIncrementSalary(){

52 double incrementedSalary=salary+((salary*(double)incrementPercentage)/100);

53 return incrementedSalary;

54 }

55 }

56

Main.java

1 import java.util.*;

2 public class Main {

4 public static void main(String[] args)


5 {

6 Scanner read=new Scanner(System.in);

8 //Fill the code

9 try

10 {

11 System.out.println("Enter the Employee Id");

12 int id=Integer.parseInt(read.nextLine());

13 System.out.println("Enter the Employee Name");

14 String name=read.nextLine();

15 System.out.println("Enter the salary");

16 double salary=Double.parseDouble(read.nextLine());

17 System.out.println("Enter the Number of Years in Experience");

18 int exp_year=Integer.parseInt(read.nextLine());

19 Employee e=new Employee(id,name,salary);

20 e.findIncrementPercentage(exp_year);

21

22 double incrementedSalary=e.calculateIncrementSalary();

23 System.out.printf("Incremented Salary %.2f", incrementedSalary);

24 }

25 catch(Exception e)

26 {

27 System.out.println(e);

28 }

29 }

30

31 }

32

You might also like