Created
July 21, 2019 04:20
-
-
Save rohitvvv/95761515a3b25573ffb6655395e86291 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Employee { | |
int employeeId; | |
String firstName; | |
String middleName; | |
String lastName; | |
int experience; | |
int salary; | |
public Employee(String firstName, String middleName, String lastName) { | |
this.firstName = firstName; | |
this.middleName = middleName; | |
this.lastName = lastName; | |
} | |
public void setSalary(int salary) { | |
this.salary = salary; | |
} | |
public void setExperience(int experience) { | |
this.experience = experience; | |
} | |
public void setEmployeeId(int x) { | |
this.employeeId = x; | |
} | |
} | |
class EmployeeBenefits { | |
Employee employee; | |
EmployeeBenefits(Employee employee){ | |
this.employee = employee; | |
} | |
public void calculateSalary() { | |
if (employee.experience < 5) { | |
employee.salary = 2000; | |
} | |
if (employee.experience > 5 && employee.experience < 10) { | |
employee.salary = 5000; | |
} | |
if (employee.experience < 15) { | |
employee.salary = 10000; | |
} | |
} | |
String getDesignation() { | |
if (employee.experience < 2) { | |
return "D2"; | |
} | |
if (employee.experience < 5 && employee.experience > 2) { | |
return "D3"; | |
} | |
if (employee.experience > 10) { | |
return "M1"; | |
} | |
return "CEO"; | |
} | |
public static void main(String[] args) { | |
Employee employee = new Employee("Mohandas","Karamchand","Gandhi"); | |
employee.setEmployeeId(1); | |
employee.experience = 10; | |
EmployeeBenefits benefits = new EmployeeBenefits(employee); | |
System.out.println(benefits.getDesignation()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment