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 #1215

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

done #1215

wants to merge 3 commits into from

Conversation

abeshle
Copy link

@abeshle abeshle commented Jan 9, 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 code meets most of the task requirements, there are a few critical issues that need to be addressed before we can approve it:

  1. Age Comparison Logic: In the selectMenByAge method, ensure that the age comparison is inclusive for both fromAge and toAge. Change p.getAge() > fromAge to p.getAge() >= fromAge to correctly include the lower bound as specified in the task description.

  2. Exception Message Formatting: The exception message in the findMinEvenNumber method should include a space after the colon, as specified in the checklist: "Can't get min value from list: " + numbers.

  3. Use of Constants: In the CandidateValidator class, replace magic numbers and strings with constants to enhance readability and maintainability. Specifically, consider using constants for:

    • The minimum years lived in Ukraine (10).
    • The nationality string ('Ukrainian').
    • The age requirement (35).

Addressing these issues will help ensure your code is both functional and maintainable. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀

✨ 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.


@Override
public boolean test(Candidate candidate) {
if (candidate.getAge() < 35) {

Choose a reason for hiding this comment

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

Consider using a constant for the age requirement (35) to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'

if (candidate.getAge() < 35) {
return false;
}
if (!(candidate.getNationality().equals("Ukrainian"))) {

Choose a reason for hiding this comment

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

Consider using a constant for the nationality string 'Ukrainian' to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'

}
int start = Integer.parseInt(periods[0]);
int finish = Integer.parseInt(periods[1]);
return (finish - start) >= 10;

Choose a reason for hiding this comment

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

Consider using a constant for the minimum years lived in Ukraine (10) to improve code readability and maintainability. This aligns with the checklist item: 'Use constants. Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator.'

.sorted()
.mapToInt(Integer::intValue)
.findFirst()
.orElseThrow(() -> new RuntimeException("Can't get min value from list:"

Choose a reason for hiding this comment

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

The exception message should include a space after the colon, as specified in the checklist: "Can't get min value from list: " + numbers.

return Collections.emptyList();
return peopleList.stream()
.filter(p -> p.getSex() == Person.Sex.MAN
&& p.getAge() > fromAge && p.getAge() <= toAge)

Choose a reason for hiding this comment

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

The age comparison should be inclusive for both fromAge and toAge. Change p.getAge() > fromAge to p.getAge() >= fromAge to include the lower bound as specified in the task description.

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 previous issues! 🎉 The CandidateValidator class now uses constants, enhancing readability and maintainability. The StreamPractice class has been improved with correct age comparison logic and exception message formatting. All critical issues have been resolved, and the code meets the task requirements. Keep up the good work and continue learning from the feedback to further improve your coding skills! 🚀

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

Copy link
Contributor

@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 ;)

Comment on lines 7 to 9
private final String nationality = "Ukrainian";
private final int age = 35;
private final int minYearsInUkraine = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

static missed. And use the correct name format: NATIONALITY...

Comment on lines 13 to 21
if (candidate.getAge() < age) {
return false;
}
if (!(candidate.getNationality().equals(nationality))) {
return false;
}
if (!candidate.isAllowedToVote()) {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you combine these conditionals?

if (!candidate.isAllowedToVote()) {
return false;
}
String[]periods = candidate.getPeriodsInUkr().split("-");
Copy link
Contributor

Choose a reason for hiding this comment

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

make separator constant field

int start = Integer.parseInt(periods[0]);
int finish = Integer.parseInt(periods[1]);
return (finish - start) >= minYearsInUkraine;

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change


return numbers.stream()
.flatMap(number -> Arrays.stream(number.split(",")))
.map(String::trim)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.map(String::trim)

Comment on lines 27 to 29
.sorted()
.mapToInt(Integer::intValue)
.findFirst()
Copy link
Contributor

Choose a reason for hiding this comment

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

use the min function

.map(i -> (i % 2 != 0) ? numbers.get(i) - 1 : numbers.get(i))
.filter(n -> n % 2 != 0)
.average()
.orElseThrow(() -> new NoSuchElementException());
Copy link
Contributor

Choose a reason for hiding this comment

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

add informative message

return peopleList.stream()
.filter(p -> p.getSex() == Person.Sex.MAN
&& p.getAge() >= fromAge && p.getAge() <= toAge)
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.collect(Collectors.toList());
.toList();

fix it everywhere

Comment on lines 76 to 79
.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
Contributor

Choose a reason for hiding this comment

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

for complicated conditional better use Predicate

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