Skip to content
Open
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
46 changes: 45 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,51 @@
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #1: "Don't begin class or method implementation with an empty line. Remove all redundant empty lines" — there is an unnecessary empty line at the start of the method body; consider removing extra blank lines to comply with the checklist.

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist item #2: "If you create a formatter, make it a constant field." Move this DateTimeFormatter to a class-level private static final constant with a proper constant name (e.g. DATE_FORMATTER) and reuse it here.


LocalDate from = LocalDate.parse(dateFrom, formatter);
LocalDate to = LocalDate.parse(dateTo, formatter);

StringBuilder report = new StringBuilder();

report.append("Report for period ").append(dateFrom)
.append(" - ").append(dateTo).append(System.lineSeparator());

for (int i = 0; i < names.length; i++) {
int salary = 0;

for (String record : data) {
String[] parts = record.split(" ");

LocalDate currentDate = LocalDate.parse(parts[0], formatter);
String employeeName = parts[1];
int hours = Integer.parseInt(parts[2]);
int rate = Integer.parseInt(parts[3]);

if (employeeName.equals(names[i]) && !currentDate.isBefore(from)
&& !currentDate.isAfter(to)) {

salary += hours * rate;
}
}

report.append(names[i])
.append(" - ")
.append(salary);

if (i < names.length - 1) {
report.append(System.lineSeparator());
}
}

return report.toString();

}

}

Loading