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
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;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class SalaryInfo {
private static DateTimeFormatter dateTimeFormatter = 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.

The DateTimeFormatter should be declared as private static final per checklist item #2. Add the final keyword to make it a constant field.


public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) {
return null;
String regex = "\\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.

The regex pattern is a constant used throughout the method. Per checklist item #9, extract magic numbers and hardcoded values to constant fields at class level.

int indexDate = 0;
int indexName = 1;
int indexWorkingHour = 2;
int indexSalary = 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.

Index values 0, 1, 2, 3 are magic numbers. Per checklist item #9, extract these to named constant fields at class level with informative names like INDEX_DATE, INDEX_NAME, etc.


LocalDate salaryDateFrom = LocalDate.parse(dateFrom, dateTimeFormatter);
LocalDate salaryDateTo = LocalDate.parse(dateTo, dateTimeFormatter);
StringBuilder stringBuilder = new StringBuilder();

stringBuilder.append("Report for period ").append(dateFrom).append(" - ").append(dateTo);
for (String name : names) {
int sumSalary = 0;
for (String dataEntry : data) {
String[] parsDatum = dataEntry.split(regex);
LocalDate currentDate = LocalDate.parse(parsDatum[indexDate], dateTimeFormatter);
if (!currentDate.isBefore(salaryDateFrom) && !currentDate.isAfter(salaryDateTo)
&& parsDatum[indexName].equals(name)) {
sumSalary += Integer.parseInt(parsDatum[indexWorkingHour])
* Integer.parseInt(parsDatum[indexSalary]);
}
}
stringBuilder.append(System.lineSeparator())
.append(name).append(" - ")
.append(sumSalary);
}
return stringBuilder.toString();
}
}
Loading