Skip to content

Commit

Permalink
implemented getSalaryInfo() method to calculate employee's salary for…
Browse files Browse the repository at this point in the history
… given period of time accordingly to quantity of working hours and hourly rate
  • Loading branch information
gekatonheyr committed Dec 19, 2024
1 parent efce797 commit 2af2ec8
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,48 @@

public class SalaryInfo {
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
StringBuilder outputString = new StringBuilder("Report for period ")
.append(dateFrom).append(" - ").append(dateTo);

for (String dataEmployeeName : names) {
int totalEmployeeSalary = 0;
for (String employeeRecord : data) {
String[] splittedEmployeeRecord = employeeRecord.split(" ");
String recordEmployeeName = splittedEmployeeRecord[1];
if (!dataEmployeeName.equals(recordEmployeeName)) {
continue;
}

String recordDate = splittedEmployeeRecord[0];
String employeeHoursOfWork = splittedEmployeeRecord[2];
String employeeSalaryPerHour = splittedEmployeeRecord[3];

String[] splittedDateFrom = dateFrom.split("\\.");
String[] splittedDateTo = dateTo.split("\\.");
String[] splittedRecordDate = recordDate.split("\\.");
if ((Integer.parseInt(splittedRecordDate[2])
<= Integer.parseInt(splittedDateFrom[2])
&& (Integer.parseInt(splittedRecordDate[1])
<= Integer.parseInt(splittedDateFrom[1])
&& (Integer.parseInt(splittedRecordDate[0])
<= Integer.parseInt(splittedDateFrom[0]))))
|| (Integer.parseInt(splittedRecordDate[2])
>= Integer.parseInt(splittedDateTo[2])
&& (Integer.parseInt(splittedRecordDate[1])
>= Integer.parseInt(splittedDateTo[1])
&& (Integer.parseInt(splittedRecordDate[0])
> Integer.parseInt(splittedDateTo[0]))))) {
continue;
}
totalEmployeeSalary += Integer.parseInt(employeeHoursOfWork)
* Integer.parseInt(employeeSalaryPerHour);
}
outputString.append(System.lineSeparator())
.append(dataEmployeeName)
.append(" - ")
.append(totalEmployeeSalary);

}
return outputString.toString();
}
}

0 comments on commit 2af2ec8

Please sign in to comment.