Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Conversation

layzimayner
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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");

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) {

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 :)

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save to constants

Comment on lines 15 to 20
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]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic numbers

Comment on lines 8 to 40
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();

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

@layzimayner layzimayner closed this by deleting the head repository Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants