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
33 changes: 32 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
package core.basesyntax;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is an empty line between the package statement and the import, meaning the class effectively begins with an empty line after the package. This goes against checklist item: Don't begin class or method implementation with an empty line. Remove all redundant empty lines. Remove the redundant blank line after the package declaration.

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;
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: If you create a formatter, make it a constant field. You should declare the DateTimeFormatter as a private static final constant in the class instead of creating it inside the method.

LocalDate fromDate = LocalDate.parse(dateFrom, formatter);
LocalDate toDate = LocalDate.parse(dateTo, formatter);

StringBuilder salaryInfo = new StringBuilder("Report for period "

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 line participates in constructing the header using hardcoded string literals. This violates checklist item: Any magic numbers should be constants (applied also to hardcoded strings). Consider extracting the header prefix (e.g. "Report for period " and the separator " - ") into private static final string constants.

+ dateFrom + " - " + dateTo);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to line 12, this continues building the header with inline string values. Per checklist item Any magic numbers should be constants, move these hardcoded strings into well-named constant fields.


for (String name : names) {
int totalEarned = 0;
for (String dataName : data) {
String[] parts = dataName.split(" ");

if (!name.equals(parts[1])) {
continue;
}
LocalDate recordDate = LocalDate.parse(parts[0], formatter);

if (!recordDate.isBefore(fromDate) && !recordDate.isAfter(toDate)) {
int hours = Integer.parseInt(parts[2]);
int rate = Integer.parseInt(parts[3]);
totalEarned += hours * rate;
}
}
salaryInfo.append(System.lineSeparator())
.append(name)
.append(" - ")
.append(totalEarned);
}
return salaryInfo.toString();
}
}
Loading