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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty lines at the start of method implementation violate checklist #1. Remove this empty line.

StringBuilder result = new StringBuilder("Report for period " + dateFrom + " - " + dateTo
+ "\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.

Checklist #7 violation: Use System.lineSeparator() instead of \n for line breaks.

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.

Checklist #2 violation: DateTimeFormatter should be a constant field (private static final), not a local variable. Move it outside the method.

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

for (String name : names) {
int totalSalary = 0;

for (String records : data) {
Comment on lines +19 to +20

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Two empty lines before the inner loop are redundant. Remove extra empty lines per checklist #1.

String[] dataParts = records.split(" ");
LocalDate currentDate = LocalDate.parse(dataParts[0], formatter);
String currentName = dataParts[1];
int currentHours = Integer.parseInt(dataParts[2]);
int currentRate = Integer.parseInt(dataParts[3]);
int salary = currentHours * currentRate;

if (name.equals(currentName)
&& !currentDate.isBefore(from)
&& !currentDate.isAfter(to)) {
totalSalary += salary;
}

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line inside the if block is redundant. Remove per checklist #1.

result.append(name)
.append(" - ")
.append(totalSalary)
.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.

Checklist #7 violation: Use System.lineSeparator() instead of \n for line breaks.

result.deleteCharAt(result.length() - 1);
return result.toString();
}

}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Empty line before class closing brace is redundant. Remove per checklist #1.

Loading