-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implemented method getSalaryInfo with solution #1587
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 1 commit
b674f6c
433ef05
e69da82
04ca9b9
d792121
890317f
8221927
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,34 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| public class SalaryInfo { | ||
| private final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
|
|
||
| public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
| return null; | ||
| StringBuilder salaryInfo = new StringBuilder(); | ||
| LocalDate from = LocalDate.parse(dateFrom, FORMATTER); | ||
| LocalDate to = LocalDate.parse(dateTo, FORMATTER); | ||
|
|
||
| salaryInfo.append("Report for period ").append(dateFrom).append(" - ").append(dateTo).append("\n"); | ||
|
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 #7: "Use System.lineSeparator". Instead of appending |
||
|
|
||
| for (String name : names) { | ||
| int salary = 0; | ||
| for (String datum : data) { | ||
| String[] parts = datum.split("\\s+"); | ||
|
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 likely violates checklist item #9: "Any magic numbers should be constants" because indices |
||
| LocalDate currentDate = 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. Same concern as at line 19 regarding magic numbers: using |
||
| if (name.equals(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. Using |
||
| if (!currentDate.isBefore(from) && !currentDate.isAfter(to)) { | ||
| salary += Integer.parseInt(parts[2]) * 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. Using |
||
| } | ||
| } | ||
| } | ||
| salaryInfo.append(name) | ||
| .append(" - ") | ||
| .append(salary) | ||
| .append("\n"); | ||
|
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 also uses a hardcoded |
||
| } | ||
| 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.
This violates checklist item #2: "If you create a formatter, make it a constant field." Here
FORMATTERisfinalbut notstatic; it should beprivate static final DateTimeFormatter FORMATTER = ...to be a true constant field, consistent with its uppercase name.