Skip to content

Practice task#1409

Open
mate-student26 wants to merge 8 commits into
mate-academy:mainfrom
mate-student26:PracticeTask
Open

Practice task#1409
mate-student26 wants to merge 8 commits into
mate-academy:mainfrom
mate-student26:PracticeTask

Conversation

@mate-student26

Copy link
Copy Markdown

No description provided.

Michal Brynkiewicz added 2 commits May 13, 2026 10:12

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +52 to +53
return peopleList.stream()
.filter(p -> p.getSex() == Person.Sex.MAN

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist requirement: Enum values must be compared using equals() method, not ==. The Person.Sex is an enum, so use equals() instead.

Comment on lines +26 to +27
.orElseThrow(() -> new RuntimeException(
"Cant't get min value from list: " + numbers));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The exception message contains a typo: 'Cant't' should be "Can't" (with apostrophe, not backtick). The checklist specifies the exact message format.

Comment on lines +35 to +40
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +70 to +73
return peopleList.stream()
.filter(p -> (p.getSex() == Person.Sex.MAN
&& (p.getAge() >= fromAge && p.getAge() <= maleToAge))
|| (p.getSex() == Person.Sex.WOMAN &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist requirement: Enum values must be compared using equals() method, not ==.

Comment on lines +84 to +85
return peopleList.stream()
.filter(p -> p.getSex() == Person.Sex.WOMAN && p.getAge() >= femaleAge)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This violates checklist requirement: Enum values must be compared using equals() method, not ==.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +26 to +27
.orElseThrow(() -> new RuntimeException(
"Cant't get min value from list: " + numbers));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Comment on lines 35 to +41
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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment on lines +53 to +54
return peopleList.stream()
.filter(p -> p.getSex() == Person.Sex.MAN

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Checklist violation: Use equals() method instead of == operator for Enum comparison. Replace p.getSex() == Person.Sex.MAN with p.getSex().equals(Person.Sex.MAN).

Comment on lines +71 to +75
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)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

import model.Candidate;
import model.Cat;
import model.Person;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Static methods cannot be overridden. Remove the @OverRide annotation or convert to instance method if you intend to implement Predicate interface properly.

Comment on lines +28 to +29
.orElseThrow(() -> new RuntimeException(
"Cant't get min value from list: " + numbers));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 slade13 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:

Suggested change
&& periodInUkrConvertedToYears(candidate) > MIN_LIVE_PERIOD;
&& periodInUkrConvertedToYears(candidate) >= MIN_LIVE_PERIOD;

Comment on lines +7 to +9
public static final int fromAge = 35;
public static final String nationality = "Ukrainian";
public static final int MIN_LIVE_PERIOD = 10;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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:

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The method periodInUkrConvertedToYears() is used only inside CandidateValidator, so it should be private. Also, the name can be simplified to something like getYearsInUkraine().

Comment on lines +22 to +28
.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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This works correctly, but you can use primitive streams to avoid unnecessary boxing:

Suggested change
.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));

@mate-student26 mate-student26 requested a review from slade13 May 14, 2026 11:09
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