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
29 changes: 28 additions & 1 deletion 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 {
private final 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." Here FORMATTER is final but not static; it should be private static final DateTimeFormatter FORMATTER = ... to be a true constant field, consistent with its uppercase name.


public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
StringBuilder salaryInfo = new StringBuilder();
LocalDate from = LocalDate.parse(dateFrom, FORMATTER);
LocalDate to = LocalDate.parse(dateTo, FORMATTER);

salaryInfo.append("Report for period ").append(dateFrom).append(" - ").append(dateTo).append("\n");

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 #7: "Use System.lineSeparator". Instead of appending "\n", use System.lineSeparator() to ensure correct line separators across OSes.


for (String name : names) {
int salary = 0;
for (String datum : data) {
String[] parts = datum.split("\\s+");

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 likely violates checklist item #9: "Any magic numbers should be constants" because indices parts[0], parts[1], parts[2], parts[3] are hardcoded. Consider introducing named constants for these positions to make the code more self-documenting and avoid magic numbers.

LocalDate currentDate = LocalDate.parse(parts[0], 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.

Same concern as at line 19 regarding magic numbers: using parts[0] directly without a named constant may violate checklist item #9. Consider defining a constant for the date index.

if (name.equals(parts[1])) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using parts[1] directly follows the same magic-number pattern; to comply with checklist item #9, consider using a named constant for the employee name index.

if (!currentDate.isBefore(from) && !currentDate.isAfter(to)) {
salary += Integer.parseInt(parts[2]) * Integer.parseInt(parts[3]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Using parts[2] and parts[3] directly for hours and rate again introduces magic numbers; per checklist item #9, consider extracting these indices as descriptive constants.

}
}
}
salaryInfo.append(name)
.append(" - ")
.append(salary)
.append("\n");

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 also uses a hardcoded "\n", violating checklist item #7 which requires System.lineSeparator() instead of explicit newline characters.

}
return salaryInfo.toString();
}
}
Loading