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

done #1393

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

done #1393

wants to merge 2 commits into from

Conversation

xMaXD
Copy link

@xMaXD xMaXD commented Jan 12, 2025

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.


Thank you for your hard work on this Pull Request! 😊 While your solution meets most of the task requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Date Parsing Exception Handling: Throwing an ArrayIndexOutOfBoundsException for a wrong date format is not appropriate. Consider using a more descriptive exception like IllegalArgumentException to indicate an invalid input format. This will make your code more robust and easier to debug.

  2. Regex Pattern for Splitting Dates: The regex pattern split("[\\.]") is incorrect for splitting by dot. It should be split("\\.") to correctly split the date string by periods. This change is necessary to ensure that the date parsing works as expected.

Please address these issues to improve the functionality and clarity of your code. Once these changes are made, we can proceed with approving your Pull Request. Keep up the great work! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

}

public LocalDate parseDate(String date) {
String[] parsedDate = date.split("[\\\\.]");

Choose a reason for hiding this comment

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

The regex pattern in split("[\\.]") is incorrect for splitting by dot. It should be split("\\.") to correctly split the date string by periods.

Comment on lines 64 to 65
throw new ArrayIndexOutOfBoundsException("Wrong date format. Got: "
+ date + " Should be dd.mm.yyyy format.");

Choose a reason for hiding this comment

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

Throwing ArrayIndexOutOfBoundsException for a wrong date format is not appropriate. Consider using a more descriptive exception like IllegalArgumentException to indicate an invalid input format.

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 your implementation! 🎉 Your code meets the task requirements and constraints effectively. Here are some key points from the review:

  • The Employee and Main classes are implemented correctly with no critical issues.
  • The SalaryInfo class is mostly well-implemented, but there are a few critical issues to address:
    1. Date Parsing Exception Handling: You've improved the code by correctly throwing an IllegalArgumentException for wrong date formats. This is a positive change from the previous ArrayIndexOutOfBoundsException.
    2. Regex Pattern for Splitting Dates: The use of split("\\.") is correct and resolves previous issues.

Overall, your code aligns well with the task description and checklist. However, ensure that exception messages are clear and informative for better debugging.

Keep up the good work, and remember to address these issues in future projects to enhance your coding skills. Your effort and progress are commendable, and this approval is to encourage you to continue learning and improving! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! Let’s improve your solution ;)

package core.basesyntax;

public class Main {
public static void main(String[] args) {

Choose a reason for hiding this comment

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

You use the main class to test your solution. But don’t push it to GitHub! Let’s remove this class

Comment on lines +61 to 71
public LocalDate parseDate(String date) {
String[] parsedDate = date.split("\\.");
if (parsedDate.length != 3) {
throw new IllegalArgumentException("Wrong date format. Got: "
+ date + " Should be dd.mm.yyyy format.");
}
int day = Integer.parseInt(parsedDate[0]);
int month = Integer.parseInt(parsedDate[1]);
int year = Integer.parseInt(parsedDate[2]);
return LocalDate.of(year, month, day);
}

Choose a reason for hiding this comment

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

Let’s replace it using DateTimeFormatter (make it a constant field)

return "Report for period " + (dateFrom) + (" - ") + (dateTo) + result;
}

public boolean isDateInRange(String date, String dateFrom, String dateTo) {

Choose a reason for hiding this comment

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

this method should be private

Comment on lines +36 to +40
} catch (NumberFormatException e) {
System.out.println("Invalid number format at index " + i);
} catch (DateTimeException e1) {
System.out.println("Invalid date format at index " + i + ". Should be dd.mm.yyyy");
}

Choose a reason for hiding this comment

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

remove the try-catch block. You don’t have any specific logic for these exceptions.

Comment on lines +46 to +49
result.append(System.lineSeparator()).append(names[i]).append(" - ").append(salary);
totalSalary += employeeSalaries[i];
}
return "Report for period " + (dateFrom) + (" - ") + (dateTo) + result;

Choose a reason for hiding this comment

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

use constants for literals and magic numbers

return null;
int[] employeeSalaries = new int[names.length];

for (int i = 0; i < data.length; i++) {

Choose a reason for hiding this comment

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

two loops are enough for this task, but you have three (let’s fix it)

employee.setName(infoFromData[1]);

try {
if (infoFromData.length >= 4) {

Choose a reason for hiding this comment

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

you don’t need this check, so let’s remove it.

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.

3 participants