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
55 changes: 54 additions & 1 deletion src/main/java/core/basesyntax/SalaryInfo.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,60 @@
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.

This still violates the checklist item: "Don't begin class or method implementation with an empty line. Remove all redundant empty lines". There is an empty line between the package declaration and the import statements; remove that redundant blank line so the class doesn’t start with an empty line.

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

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: Don’t use two-dimension arrays and HashMap(or any other Map). You are importing and using HashMap/Map to track salaries, but the task requires solving it without any Map implementations.


public class SalaryInfo {

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 shows the class starting after an empty line following the package declaration, which conflicts with the checklist requirement: Don't begin class or method implementation with an empty line. Remove all redundant empty lines.


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: If you create a formatter, make it a constant field. The formatter here is an instance field and not a constant (should be private static final DateTimeFormatter FORMATTER = ...; with constant-style naming).


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

Map<String, Integer> salary = new HashMap<>();
for (String name : names) {
salary.put(name, 0);
}

for (String row : data) {
String[] parts = row.split(" ");
LocalDate currentDate = LocalDate.parse(parts[0], formatter);
if (currentDate.isBefore(from) || currentDate.isAfter(to)) {
continue;
}

String name = parts[1];

if (!salary.containsKey(name)) {
continue;
}

int hours = Integer.parseInt(parts[2]);
int rate = Integer.parseInt(parts[3]);
int earned = hours * rate;
salary.put(name, salary.get(name) + earned);
}

StringBuilder builder = new StringBuilder();

builder.append("Report for period ")
.append(dateFrom)
.append(" - ")
.append(dateTo)
.append(System.lineSeparator());

for (int i = 0; i < names.length; i++) {
builder.append(names[i])
.append(" - ")
.append(salary.get(names[i]));

if (i < names.length - 1) {
builder.append(System.lineSeparator());
}

}
return builder.toString();
}
}
Loading