Skip to content

Instantly share code, notes, and snippets.

@rohitvvv
Created July 21, 2019 04:20
Show Gist options
  • Save rohitvvv/95761515a3b25573ffb6655395e86291 to your computer and use it in GitHub Desktop.
Save rohitvvv/95761515a3b25573ffb6655395e86291 to your computer and use it in GitHub Desktop.
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