Skip to content
Open
Changes from 1 commit
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
34 changes: 33 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
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;
StringBuilder result = new StringBuilder();
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.

According to checklist item #2, if you create a DateTimeFormatter, it should be a constant field, not a local variable. Move it to the top of the class as a static final field.

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 format pattern "dd.MM.yyyy" is a magic number. According to checklist item #9, it should be declared as a constant with an informative name (e.g., DATE_FORMAT_PATTERN).

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

result.append("Report for period ")
.append(dateFrom)
.append(" - ")
.append(dateTo);

for (String name : names) {
int salary = 0;

for (String line : data) {
String[] info = line.split(" ");

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 magic number " " (space character used for splitting data strings) should be extracted as a private static final constant with an informative name, as required by checklist item #8.

LocalDate date = LocalDate.parse(info[0], formatter);

if (info[1].equals(name) && !date.isBefore(from) && !date.isAfter(to)) {
salary += Integer.parseInt(info[2]) * Integer.parseInt(info[3]);
}

}

result.append(System.lineSeparator())
.append(name)
.append(" - ")
.append(salary);
}

return result.toString();
}
}
Loading