Skip to content

Instantly share code, notes, and snippets.

@ppajdek
Created June 24, 2020 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ppajdek/38dc3545d769eb31cdb5efe2eebe6b85 to your computer and use it in GitHub Desktop.
Save ppajdek/38dc3545d769eb31cdb5efe2eebe6b85 to your computer and use it in GitHub Desktop.
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