-
Notifications
You must be signed in to change notification settings - Fork 1.5k
implement method getSalaryInfo() to generate salary report #1482
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 2 commits
3df05a9
18c61ec
abc2a36
e690e20
96f2ffe
e97e4ad
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,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; | ||
| DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
| LocalDate from = LocalDate.parse(dateFrom, formatter); | ||
| LocalDate to = LocalDate.parse(dateTo, formatter); | ||
|
|
||
| int[] salary = new int[names.length]; | ||
|
|
||
| for (String record : data) { | ||
| String[] parts = record.split(" "); | ||
|
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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants. |
||
| LocalDate workDate = LocalDate.parse(parts[0], formatter); | ||
|
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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants. |
||
| String name = parts[1]; | ||
|
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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants. |
||
| int hours = Integer.parseInt(parts[2]); | ||
|
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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants. |
||
| int income = Integer.parseInt(parts[3]); | ||
|
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 the checklist item: "Any magic numbers (hardcoded values with unclear meaning) must be moved to constant fields with informative names." The indices 0, 1, 2, 3 used for parts[] should be replaced with named constants. |
||
|
|
||
| if ((workDate.isAfter(from) || workDate.isEqual(from)) | ||
| && (workDate.isBefore(to) || workDate.isEqual(to))) { | ||
| for (int i = 0; i < names.length; ++i) { | ||
| if (names[i].equals(name)) { | ||
| salary[i] += income * hours; | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| StringBuilder builder = new StringBuilder("Report for period " + dateFrom | ||
| + " - " + dateTo); | ||
| for (int i = 0; i < names.length; ++i) { | ||
| builder.append(System.lineSeparator()) | ||
| .append(names[i]) | ||
| .append(" - ") | ||
| .append(salary[i]); | ||
| } | ||
| 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 violates the requirement: "If a date formatter is created, it must be a constant field." The DateTimeFormatter should be declared as a private static final constant, not inside the method.