-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
tests fails cuz of stupid separator #1310
base: master
Are you sure you want to change the base?
Changes from 1 commit
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,32 @@ | ||||||||||||||||
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) { | ||||||||||||||||
Comment on lines
6
to
7
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.
Suggested change
|
||||||||||||||||
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. Since the formatter is created here and used multiple times, it should be made a constant field. This will make your code easier to understand and maintain. 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. |
||||||||||||||||
LocalDate startDate = LocalDate.parse(dateFrom, formatter); | ||||||||||||||||
LocalDate endDate = LocalDate.parse(dateTo, formatter); | ||||||||||||||||
|
||||||||||||||||
StringBuilder report = new StringBuilder(); | ||||||||||||||||
report.append("Report for period ").append(dateFrom).append(" - ").append(dateTo); | ||||||||||||||||
|
||||||||||||||||
for (String name : names) { | ||||||||||||||||
int salary = 0; | ||||||||||||||||
for (String line : data) { | ||||||||||||||||
String[] parts = line.split(" "); | ||||||||||||||||
if (parts[1].equals(name)) { | ||||||||||||||||
LocalDate workDate = LocalDate.parse(parts[0], formatter); | ||||||||||||||||
if (workDate.isAfter(startDate.minusDays(1)) && workDate.isBefore(endDate.plusDays(1))) { | ||||||||||||||||
int hours = Integer.parseInt(parts[2]); | ||||||||||||||||
int rate = Integer.parseInt(parts[3]); | ||||||||||||||||
salary += hours * rate; | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
} | ||||||||||||||||
report.append("\n").append(name).append(" - ").append(Integer.toString(salary)); | ||||||||||||||||
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. Instead of using '\n' for line breaks, use 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. It's better to use |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
return report.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.
The method implementation should not begin with an empty line. Please remove the empty line at the start of the method.