-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implemented method getSalaryInfo(String[] names, String[] data, Strin… #1594
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
52aef78
09c7d64
f6ad416
4c8e19b
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,39 @@ | ||
| 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; | ||
| StringBuilder result = new StringBuilder(); | ||
| 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. The date format pattern "dd.MM.yyyy" is a magic number. According to checklist item #9, it should be declared as a constant with an informative name (e.g., DATE_FORMAT_PATTERN). |
||
| LocalDate from = LocalDate.parse(dateFrom, formatter); | ||
| LocalDate to = LocalDate.parse(dateTo, formatter); | ||
|
|
||
| result.append("Report for period ") | ||
| .append(dateFrom) | ||
| .append(" - ") | ||
| .append(dateTo); | ||
|
|
||
| for (String name : names) { | ||
| int salary = 0; | ||
|
|
||
| for (String line : data) { | ||
| String[] info = line.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. The magic number " " (space character used for splitting data strings) should be extracted as a private static final constant with an informative name, as required by checklist item #8. |
||
| LocalDate date = LocalDate.parse(info[0], formatter); | ||
|
|
||
| if (info[1].equals(name) && !date.isBefore(from) && !date.isAfter(to)) { | ||
| salary += Integer.parseInt(info[2]) * Integer.parseInt(info[3]); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| result.append(System.lineSeparator()) | ||
| .append(name) | ||
| .append(" - ") | ||
| .append(salary); | ||
| } | ||
|
|
||
| return result.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.
According to checklist item #2, if you create a DateTimeFormatter, it should be a constant field, not a local variable. Move it to the top of the class as a static final field.