Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
rafael60193 committed Nov 26, 2024
1 parent efce797 commit 7fb39a1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
package core.basesyntax;

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

public class SalaryInfo {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
LocalDate dateStart = LocalDate.parse(dateFrom, formatter);
LocalDate dateEnd = LocalDate.parse(dateTo, formatter);
StringBuilder salaryReport = new StringBuilder();
salaryReport.append("Report for period ").append(dateFrom).append(" - ")
.append(dateTo).append(System.lineSeparator());
for (String name : names) {
int salaryTotal = 0;
for (String record : data) {
String[] partOfRecord = record.split(" ");
LocalDate workingDay = LocalDate.parse(partOfRecord[0], formatter);
String employeeName = partOfRecord[1];
int workingHours = Integer.parseInt(partOfRecord[2]);
int salaryPerHour = Integer.parseInt(partOfRecord[3]);
if (employeeName.equals(name) && !workingDay.isBefore(dateStart) && !workingDay.isAfter(dateEnd)) {
salaryTotal += workingHours * salaryPerHour;
}
}
salaryReport.append(name).append(" - ").append(salaryTotal).append(System.lineSeparator());
}
return salaryReport.toString();
}
}

0 comments on commit 7fb39a1

Please sign in to comment.