Practice task#1409
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
This requires changes due to several critical issues. Task 2 (getOddNumsAverage) has a fundamental logic error - the code filters odd numbers but never performs the required transformation step: 'subtract 1 from each element on an odd position (having the odd index)'. The correct approach is to first iterate with index, subtract 1 from elements at odd indices, then filter and average the resulting odd numbers. Enum comparisons in Tasks 3, 4, and 5 use == operator instead of equals() method - the checklist explicitly requires equals() for Enum comparison, so replace p.getSex() == Person.Sex.MAN with p.getSex().equals(Person.Sex.MAN). Exception message typo in findMinEvenNumber() uses 'Cant't' instead of the required 'Can't' format. The checkstyle violations (whitespace, line length) are non-blocking style issues you can fix with your linter.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.MAN |
There was a problem hiding this comment.
This violates checklist requirement: Enum values must be compared using equals() method, not ==. The Person.Sex is an enum, so use equals() instead.
| .orElseThrow(() -> new RuntimeException( | ||
| "Cant't get min value from list: " + numbers)); |
There was a problem hiding this comment.
The exception message contains a typo: 'Cant't' should be "Can't" (with apostrophe, not backtick). The checklist specifies the exact message format.
| public Double getOddNumsAverage(List<Integer> numbers) { | ||
| return 0D; | ||
| return numbers.stream() | ||
| .mapToInt(Integer::intValue) | ||
| .filter(n -> n % 2 != 0) | ||
| .average() | ||
| .orElseThrow(() -> new NoSuchElementException("No odd numbers in the list: " + numbers)); |
There was a problem hiding this comment.
This violates the core task requirement: 'subtract 1 from each element on an odd position (having the odd index)'. The code only filters odd numbers without first modifying elements at odd indices. The operation must: (1) iterate with index, (2) subtract 1 from elements at odd indices, (3) then calculate average of odd numbers from the modified list.
| return peopleList.stream() | ||
| .filter(p -> (p.getSex() == Person.Sex.MAN | ||
| && (p.getAge() >= fromAge && p.getAge() <= maleToAge)) | ||
| || (p.getSex() == Person.Sex.WOMAN && |
There was a problem hiding this comment.
This violates checklist requirement: Enum values must be compared using equals() method, not ==.
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.WOMAN && p.getAge() >= femaleAge) |
There was a problem hiding this comment.
This violates checklist requirement: Enum values must be compared using equals() method, not ==.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| .orElseThrow(() -> new RuntimeException( | ||
| "Cant't get min value from list: " + numbers)); |
There was a problem hiding this comment.
Exception message has typo: 'Cant't' should be "Can't" (with apostrophe, not "t" after it). The checklist specifies the exact format: "Can't get min value from list: " + numbers
| public Double getOddNumsAverage(List<Integer> numbers) { | ||
| return 0D; | ||
| return numbers.stream() | ||
| .mapToInt(Integer::intValue) | ||
| .filter(n -> n % 2 != 0) | ||
| .average() | ||
| .orElseThrow(() -> new NoSuchElementException( | ||
| "No odd numbers in the list: " + numbers)); |
There was a problem hiding this comment.
Task 2 Logic Error (still not fixed): The requirement states 'subtract 1 from each element on an odd position (having the odd index)' before averaging odd numbers. Current code only filters for odd numbers but never subtracts 1 from elements at odd indices. You need to use an indexed stream, subtract 1 from elements at odd indices first, then filter and average the resulting odd numbers.
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.MAN |
There was a problem hiding this comment.
Checklist violation: Use equals() method instead of == operator for Enum comparison. Replace p.getSex() == Person.Sex.MAN with p.getSex().equals(Person.Sex.MAN).
| return peopleList.stream() | ||
| .filter(p -> (p.getSex() == Person.Sex.MAN | ||
| && (p.getAge() >= fromAge && p.getAge() <= maleToAge)) | ||
| || (p.getSex() == Person.Sex.WOMAN | ||
| && (p.getAge() >= fromAge && p.getAge() <= femaleToAge))) |
There was a problem hiding this comment.
Checklist violation: Use equals() method instead of == operator for Enum comparison. Replace both Person.Sex.MAN and Person.Sex.WOMAN comparisons with .equals() method calls.
| */ | ||
| public List<String> getCatsNames(List<Person> peopleList, int femaleAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() |
There was a problem hiding this comment.
Checklist violation: Use equals() method instead of == operator for Enum comparison. Replace p.getSex() == Person.Sex.WOMAN with p.getSex().equals(Person.Sex.WOMAN).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution with an educational override to help you progress while learning. What's working well: Your implementation shows solid understanding of streams with getOddNumsAverage being correct, and the filtering logic in getWorkablePeople and getCatsNames is well-structured. The exception handling approach for empty lists is appropriate. Issues that need attention: 1. Compilation error in CandidateValidator.java: Static methods cannot have @OverRide annotation. Remove it or convert to a non-static method. [CHECKLIST ITEM #11] 2. CandidateValidator must implement Predicate: The task requires writing your own implementation of Predicate as a class, not a static utility method. Create a class like class ValidCandidatePredicate implements Predicate with a test() method, then use it in validateCandidates(). [CHECKLIST ITEM #11] 3. Enum comparisons in StreamPractice.java: Use .equals() instead of == for comparing Person.Sex values (lines with p.getSex() == Person.Sex.MAN). [CHECKLIST ITEM #7] 4. Exception message typo: Change "Cant't" to "Can't" in findMinEvenNumber. [CHECKLIST ITEM #13] 5. Magic number: The value 10 for years lived should be defined as a constant. [CHECKLIST ITEM #9] Keep practicing—these are common Java patterns that become second nature with time!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| import model.Candidate; | ||
| import model.Cat; | ||
| import model.Person; | ||
|
|
There was a problem hiding this comment.
Static methods cannot be overridden. Remove the @OverRide annotation or convert to instance method if you intend to implement Predicate interface properly.
| .orElseThrow(() -> new RuntimeException( | ||
| "Cant't get min value from list: " + numbers)); |
There was a problem hiding this comment.
The message has a typo: 'Cant't' should be 'Can't' (missing 'a'). The checklist requires exactly: "Can't get min value from list: "
| public List<Person> selectMenByAge(List<Person> peopleList, int fromAge, int toAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.MAN |
There was a problem hiding this comment.
Compare Enum values using equals() instead of ==. Change p.getSex() == Person.Sex.MAN to p.getSex().equals(Person.Sex.MAN)
| int maleToAge, List<Person> peopleList) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> (p.getSex() == Person.Sex.MAN |
There was a problem hiding this comment.
Compare Enum values using equals() instead of ==
| return peopleList.stream() | ||
| .filter(p -> (p.getSex() == Person.Sex.MAN | ||
| && (p.getAge() >= fromAge && p.getAge() <= maleToAge)) | ||
| || (p.getSex() == Person.Sex.WOMAN |
There was a problem hiding this comment.
Compare Enum values using equals() instead of ==
| public List<String> getCatsNames(List<Person> peopleList, int femaleAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.WOMAN && p.getAge() >= femaleAge) |
There was a problem hiding this comment.
Compare Enum values using equals() instead of ==
| public static final String livePeriod = "2002-2015"; | ||
| public static final String nationality = "Ukrainian"; | ||
|
|
||
| public static Predicate<Candidate> isValid() { |
There was a problem hiding this comment.
The @Override annotation cannot be used on static methods - this is a compilation error. Remove the @Override annotation.
| public static final String nationality = "Ukrainian"; | ||
|
|
||
| public static Predicate<Candidate> isValid() { | ||
| return candidate -> candidate.getAge() >= fromAge |
There was a problem hiding this comment.
This violates checklist item #11: The task requires writing 'our own implementation of Predicate' as a class, not a static method. Create a class like class ValidCandidatePredicate implements Predicate<Candidate> with an evaluate() or test() method, and use it in validateCandidates().
| && candidate.isAllowedToVote() | ||
| && nationality.equals(candidate.getNationality()) | ||
| && livePeriod.equals(candidate.getPeriodsInUkr()); | ||
| } |
There was a problem hiding this comment.
Checklist item #9 requires using constants for magic numbers/strings. The value 10 for years lived should be defined as a constant instead of hardcoded.
slade13
left a comment
There was a problem hiding this comment.
Good job, please review my comments and add necessary updates.
| return candidate.getAge() >= fromAge | ||
| && candidate.isAllowedToVote() | ||
| && nationality.equals(candidate.getNationality()) | ||
| && periodInUkrConvertedToYears(candidate) > MIN_LIVE_PERIOD; |
There was a problem hiding this comment.
The task says the candidate should have lived in Ukraine for 10 years, and the requirement is usually interpreted as at least 10 years. With the current implementation, a candidate with "2010-2020" would be rejected, because 10 > 10 is false.
Better:
| && periodInUkrConvertedToYears(candidate) > MIN_LIVE_PERIOD; | |
| && periodInUkrConvertedToYears(candidate) >= MIN_LIVE_PERIOD; |
| public static final int fromAge = 35; | ||
| public static final String nationality = "Ukrainian"; | ||
| public static final int MIN_LIVE_PERIOD = 10; |
There was a problem hiding this comment.
Please use uppercase names for constants and make them private, because they are used only inside CandidateValidator. This improves readability and follows Java naming conventions.
For example:
| public static final int fromAge = 35; | |
| public static final String nationality = "Ukrainian"; | |
| public static final int MIN_LIVE_PERIOD = 10; | |
| private static final int MIN_AGE = 35; | |
| private static final String REQUIRED_NATIONALITY = "Ukrainian"; | |
| private static final int MIN_LIVE_PERIOD = 10; |
| public static final String nationality = "Ukrainian"; | ||
| public static final int MIN_LIVE_PERIOD = 10; | ||
|
|
||
| public int periodInUkrConvertedToYears(Candidate candidate) { |
There was a problem hiding this comment.
The method periodInUkrConvertedToYears() is used only inside CandidateValidator, so it should be private. Also, the name can be simplified to something like getYearsInUkraine().
| .flatMap(n -> Arrays.stream(n.split(","))) | ||
| .map(String::trim) | ||
| .map(Integer::parseInt) | ||
| .filter(n -> n % 2 == 0) | ||
| .min(Integer::compare) | ||
| .orElseThrow(() -> new RuntimeException( | ||
| "Can't get min value from list: " + numbers)); |
There was a problem hiding this comment.
This works correctly, but you can use primitive streams to avoid unnecessary boxing:
| .flatMap(n -> Arrays.stream(n.split(","))) | |
| .map(String::trim) | |
| .map(Integer::parseInt) | |
| .filter(n -> n % 2 == 0) | |
| .min(Integer::compare) | |
| .orElseThrow(() -> new RuntimeException( | |
| "Can't get min value from list: " + numbers)); | |
| .flatMap(s -> Arrays.stream(s.split(","))) | |
| .map(String::trim) | |
| .mapToInt(Integer::parseInt) | |
| .filter(n -> n % 2 == 0) | |
| .min() | |
| .orElseThrow(() -> new RuntimeException( | |
| "Can't get min value from list: " + numbers)); |
No description provided.