-
Notifications
You must be signed in to change notification settings - Fork 1.5k
sallary info solution #1582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
sallary info solution #1582
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,60 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: |
||
|
|
||
| public class SalaryInfo { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: |
||
|
|
||
| private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: |
||
|
|
||
| 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(); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
packagedeclaration and theimportstatements; remove that redundant blank line so the class doesn’t start with an empty line.