-
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
developed method #1318
developed method #1318
Conversation
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.
Great job on the Pull Request! Just a couple of minor style adjustments for the future - remember to avoid unnecessary empty lines at the beginning of methods and consider defining formatters as constant fields for better code clarity and maintainability. Keep up the good work! 👍💻
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
int[] sums = new int[names.length]; | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); |
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.
If you create a formatter, make it a constant field. That will make your code easier to understand and if you use it in several places in your code you will be able to change its value easily with one action(change variable declaration).
public class SalaryInfo { | ||
|
||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { |
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.
Don't begin method implementation with an empty line. Remove all redundant empty lines, be careful :)
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.
Great job on addressing the core functionality of the task! 🌟 Your code looks solid, and there are no critical issues that would warrant a change request. Keep up the good work and always aim for improvement by considering the feedback provided. Happy coding! 💻🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
public class SalaryInfo { | ||
public String getSalaryInfo(String[] names, String[] data, String dateFrom, String dateTo) { | ||
return null; | ||
int[] sums = new int[names.length]; | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); |
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.
Save to constants
LocalDate entryDate = LocalDate.parse(parts[0], formatter); | ||
if ((entryDate.isEqual(from) || entryDate.isAfter(from)) | ||
&& (entryDate.isEqual(to) || entryDate.isBefore(to))) { | ||
String employeeName = parts[1]; | ||
int hoursWorked = Integer.parseInt(parts[2]); | ||
int salaryPerHour = Integer.parseInt(parts[3]); |
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.
magic numbers
int[] sums = new int[names.length]; | ||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); | ||
LocalDate from = LocalDate.parse(dateFrom, formatter); | ||
LocalDate to = LocalDate.parse(dateTo, formatter); | ||
|
||
for (String entry : data) { | ||
String[] parts = entry.split(" "); | ||
LocalDate entryDate = LocalDate.parse(parts[0], formatter); | ||
if ((entryDate.isEqual(from) || entryDate.isAfter(from)) | ||
&& (entryDate.isEqual(to) || entryDate.isBefore(to))) { | ||
String employeeName = parts[1]; | ||
int hoursWorked = Integer.parseInt(parts[2]); | ||
int salaryPerHour = Integer.parseInt(parts[3]); | ||
|
||
for (int j = 0; j < names.length; j++) { | ||
if (employeeName.equals(names[j])) { | ||
sums[j] += salaryPerHour * hoursWorked; | ||
} | ||
} | ||
} | ||
} | ||
|
||
StringBuilder result = new StringBuilder(); | ||
result.append("Report for period ").append(dateFrom).append(" - ") | ||
.append(dateTo).append(System.lineSeparator()); | ||
for (int i = 0; i < names.length; i++) { | ||
result.append(names[i]).append(" - ").append(sums[i]); | ||
if (i < names.length - 1) { | ||
result.append(System.lineSeparator()); | ||
} | ||
} | ||
|
||
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.
divide this method for some private methods
No description provided.