Skip to content

Commit

Permalink
Solution for the task:
Browse files Browse the repository at this point in the history
- added implementation to the method getSalaryInfo(), class SalaryInfo
- added parseDate() method to the class SalaryInfo
  • Loading branch information
Dymchenko, Mykola committed Oct 23, 2024
1 parent efce797 commit 0191af6
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,48 @@
package core.basesyntax;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class SalaryInfo {
private static final int DATE_INDEX = 0;
private static final int NAME_INDEX = 1;
private static final int HOUR_INDEX = 2;
private static final int SALARY_PER_HOUR_INDEX = 3;

private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy");

public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
StringBuilder summaryReport = new StringBuilder("Report for period ");
summaryReport
.append(dateFrom)
.append(" - ")
.append(dateTo);
LocalDate startDate = parseDate(dateFrom);
LocalDate endDate = parseDate(dateTo);
for (int i = 0; i < names.length; i++) {
summaryReport.append("\n");
int salaryInfo = 0;
for (int j = 0; j < data.length; j++) {
String[] tempDataDetails = data[j].split(" ");
LocalDate employeeDate = parseDate(tempDataDetails[DATE_INDEX]);
if (names[i].equals(tempDataDetails[NAME_INDEX])) {
if (employeeDate.isAfter(startDate)
&& (employeeDate.isBefore(endDate)
|| employeeDate.isEqual(endDate))) {
salaryInfo += Integer.parseInt(tempDataDetails[HOUR_INDEX])
* Integer.parseInt(tempDataDetails[SALARY_PER_HOUR_INDEX]);
}
}
}
summaryReport
.append(names[i])
.append(" - ")
.append(salaryInfo);
}
return summaryReport.toString();
}

private static LocalDate parseDate(String dateFrom) {
return LocalDate.parse(dateFrom, FORMATTER);
}
}

0 comments on commit 0191af6

Please sign in to comment.