Skip to content
Open
Changes from 2 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
37 changes: 36 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
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;
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 the requirement: "If a date formatter is created, it must be a constant field." The DateTimeFormatter should be declared as a private static final constant, not inside the method.

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

int[] salary = new int[names.length];

for (String record : data) {
String[] parts = record.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.

This violates the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants.

LocalDate workDate = 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.

This violates the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants.

String name = 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.

This violates the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants.

int hours = Integer.parseInt(parts[2]);

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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants.

int income = 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.

This violates the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants.


if ((workDate.isAfter(from) || workDate.isEqual(from))
&& (workDate.isBefore(to) || workDate.isEqual(to))) {
for (int i = 0; i < names.length; ++i) {
if (names[i].equals(name)) {
salary[i] += income * hours;
break;
}
}
}
}

StringBuilder builder = new StringBuilder("Report for period " + dateFrom
+ " - " + dateTo);
for (int i = 0; i < names.length; ++i) {
builder.append(System.lineSeparator())
.append(names[i])
.append(" - ")
.append(salary[i]);
}
return builder.toString();
}
}