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
42 changes: 40 additions & 2 deletions src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,45 @@
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 String DATE_FORMAT_PATTERN = "dd.MM.yyyy";
private static final DateTimeFormatter formatter

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Line 8 exceeds 100 characters (104 characters). Break the formatter assignment across multiple lines with proper indentation, similar to how method parameters are formatted on lines 11-14.

= DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN);

public String getSalaryInfo(String[] names,
String[] data,
String dateFrom,
String dateTo) {
StringBuilder result = new StringBuilder();
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