-
-
Save ppajdek/38dc3545d769eb31cdb5efe2eebe6b85 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
int calculateEmployeeSalary(int[][] employeesWorkingSchedule, int employeeId, int dailySalary) { | |
int salary = 0; | |
for (int[] weekSchedule : employeesWorkingSchedule) { | |
salary += calculateWeekSalary(weekSchedule, employeeId, dailySalary); | |
} | |
return salary; | |
} | |
private int calculateWeekSalary(int[] weekSchedule, int employeeId, int dailySalary) { | |
int salary = 0; | |
for (int dayInWeek = 0; dayInWeek < NUM_OF_DAYS_IN_A_WEEK; dayInWeek++) { | |
int workingEmployeeId = weekSchedule[dayInWeek]; | |
salary += dayInWeek == SUNDAY | |
? calculateSundaySalary(employeeId, dailySalary, workingEmployeeId) | |
: calculateRegularDaySalary(employeeId, dailySalary, workingEmployeeId) | |
} | |
return salary; | |
} | |
private int calculateSundaySalary(int employeeId, int dailySalary, int workingEmployeeId) { | |
int regularDaySalary = calculateRegularDaySalary(employeeId, dailySalary, workingEmployeeId); | |
return regularDaySalary * 1.5; | |
} | |
private int calculateRegularDaySalary(int employeeId, int dailySalary, int workingEmployeeId) { | |
return workingEmployeeId == employeeId ? dailySalary : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment