Skip to content
Open

try1 #1479

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
package core.basesyntax;

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

public class SalaryInfo {
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
private static final DateTimeFormatter FORMATTER =
DateTimeFormatter.ofPattern("dd.MM.yyyy");

public String getSalaryInfo(String[] names, String[] data, String dateFrom,
String dateTo) {
StringBuilder salaryReport = new StringBuilder("Report for period "
+ dateFrom + " - " + dateTo + System.lineSeparator());
LocalDate firstDate = LocalDate.parse(dateFrom, FORMATTER);
LocalDate lastDate = LocalDate.parse(dateTo, FORMATTER);
for (String name : names) {
int fullSalary = 0;
for (String entry : data) {
String[] parts = entry.split(" ");
LocalDate date = LocalDate.parse(parts[0], FORMATTER);
if (!date.isBefore(firstDate) && !date.isAfter(lastDate)
&& name.equals(parts[1])) {
int hours = Integer.parseInt(parts[2]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The date range check uses isAfter(firstDate) and isBefore(lustDate), which excludes the boundary dates. According to the checklist, the range should be inclusive, so you should use !date.isBefore(firstDate) && !date.isAfter(lastDate).

int salaryPerHour = Integer.parseInt(parts[3]);
fullSalary += hours * salaryPerHour;
}
}
salaryReport.append(name).append(" - ").append(fullSalary)
.append(System.lineSeparator());
}
salaryReport.deleteCharAt(salaryReport.length() - 1);
return salaryReport.toString();
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning salaryMap.toString() does not match the required output format. The checklist specifies that the output should be formatted as described in the task description, not as a map string.

}