-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement SalaryInfo solution #1585
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?
Changes from all commits
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,38 @@ | ||
| 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"); | ||
|
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: |
||
| LocalDate fromDate = LocalDate.parse(dateFrom, formatter); | ||
| LocalDate toDate = LocalDate.parse(dateTo, formatter); | ||
|
|
||
| StringBuilder salaryInfo = new StringBuilder("Report for period " | ||
|
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 participates in constructing the header using hardcoded string literals. This violates checklist item: |
||
| + dateFrom + " - " + dateTo); | ||
|
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. Similar to line 12, this continues building the header with inline string values. Per checklist item |
||
|
|
||
| for (String name : names) { | ||
| int totalEarned = 0; | ||
| for (String dataName : data) { | ||
| String[] parts = dataName.split(" "); | ||
|
|
||
| if (!name.equals(parts[1])) { | ||
| continue; | ||
| } | ||
| LocalDate recordDate = LocalDate.parse(parts[0], formatter); | ||
|
|
||
| if (!recordDate.isBefore(fromDate) && !recordDate.isAfter(toDate)) { | ||
| int hours = Integer.parseInt(parts[2]); | ||
| int rate = Integer.parseInt(parts[3]); | ||
| totalEarned += hours * rate; | ||
| } | ||
| } | ||
| salaryInfo.append(System.lineSeparator()) | ||
| .append(name) | ||
| .append(" - ") | ||
| .append(totalEarned); | ||
| } | ||
| return salaryInfo.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.
There is an empty line between the package statement and the import, meaning the class effectively begins with an empty line after the package. This goes against checklist item:
Don't begin class or method implementation with an empty line. Remove all redundant empty lines. Remove the redundant blank line after the package declaration.