-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Implement SalaryInfo #1583
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?
Implement SalaryInfo #1583
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,46 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.format.DateTimeFormatter; | ||
|
|
||
| public class SalaryInfo { | ||
| static 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 "Don't begin class or method implementation with an empty line. Remove all redundant empty lines": there is an extra empty line between the class declaration and the formatter field; the class implementation should not start with a blank line. |
||
| public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
| return null; | ||
| StringBuilder stringBuilder = 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. According to checklist item "Any magic numbers should be constants / Move all hardcoded values to constant fields", the string literal |
||
| + dateFrom + " - " + dateTo); | ||
| if (names == null || data == null) { | ||
| return "No data"; | ||
| } | ||
| String[] partsOfData; | ||
| String dataName; | ||
| int workingHour; | ||
| int incomePerHour; | ||
| int calcSalary = 0; | ||
|
|
||
| LocalDate localDateFrom = LocalDate.parse(dateFrom, FORMATTER); | ||
| LocalDate localDateTo = LocalDate.parse(dateTo, FORMATTER); | ||
| for (String name : names) { | ||
| for (String datum : data) { | ||
| if (datum == null) { | ||
| continue; | ||
| } | ||
| partsOfData = datum.split(" "); | ||
| dataName = partsOfData[1]; | ||
| workingHour = Integer.parseInt(partsOfData[2]); | ||
| incomePerHour = Integer.parseInt(partsOfData[3]); | ||
| LocalDate localDate = LocalDate.parse(partsOfData[0], FORMATTER); | ||
| if (name.equals(dataName) | ||
| && !localDate.isBefore(localDateFrom) | ||
| && !localDate.isAfter(localDateTo)) { | ||
| calcSalary = calcSalary + (workingHour * incomePerHour); | ||
| } | ||
| } | ||
| stringBuilder.append(System.lineSeparator()).append(name) | ||
| .append(" - ").append(calcSalary); | ||
| calcSalary = 0; | ||
| } | ||
| return stringBuilder.toString(); | ||
| } | ||
| } | ||
|
|
||
|
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 "Don't begin class or method implementation with an empty line. Remove all redundant empty lines": there is an extra empty line at the end of the file after the closing brace of the class. |
||
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 "Don't begin class or method implementation with an empty line. Remove all redundant empty lines": there is an empty line between the package declaration and the first import, which counts as starting the class file with an unnecessary empty line.