Created
February 15, 2021 21:46
-
-
Save trikitrok/cfacfcbeb54be0343715af19cb1c3343 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
// From Code Smells – Part II, Ana Nogal https://www.ananogal.com/blog/code-smells-part-two/ | |
public enum EmployeeType { | |
Worker, | |
Supervisor, | |
Manager | |
} | |
public class Employee { | |
private float salary; | |
private float bonusPercentage; | |
private EmployeeType employeeType; | |
public Employee(float salary, float bonusPercentage, EmployeeType employeeType) { | |
this.salary = salary; | |
this.bonusPercentage = bonusPercentage; | |
this.employeeType = employeeType; | |
} | |
public float calculateSalary() { | |
switch (employeeType) { | |
case EmployeeType.Worker: | |
return salary; | |
case EmployeeType.Supervisor: | |
return salary + (bonusPercentage * 0.5F); | |
case EmployeeType.Manager: | |
return salary + (bonusPercentage * 0.7F); | |
} | |
return 0.0F; | |
} | |
public float calculateYearBonus() { | |
switch (employeeType) { | |
case EmployeeType.Worker: | |
return 0; | |
case EmployeeType.Supervisor: | |
return salary + salary * 0.7F; | |
case EmployeeType.Manager: | |
return salary + salary * 1.0F; | |
} | |
return 0.0F; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment