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

add getRandomColor and getRandomBall foo #1729

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

Conversation

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


Thank you for your hard work on this Pull Request! 😊 While your solution is almost there, there are a couple of critical issues that need to be addressed before we can approve it:

  1. Ball Array Initialization: In the Application class, the enhanced for-loop does not correctly update the balls array with the new Ball objects. This is a critical issue as it affects the core functionality of storing Ball objects. Please use a traditional for-loop to iterate over the array indices and assign the new Ball objects directly to the array elements.

  2. Enum String Representation: In the ColorSupplier class, using toString() to get the string representation of the enum constant is not recommended. Please switch to using the name() method for a more reliable result.

Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you have any questions or need further assistance. 🌟

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

Comment on lines 8 to 11
for (Ball ball: balls) {
ball = new Lottery().getRandomBall();
System.out.println(ball);
}

Choose a reason for hiding this comment

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

The enhanced for-loop does not update the balls array with the new Ball objects. Instead, it assigns the new Ball to the ball variable, which is a copy of the array element. To fix this, use a traditional for-loop to iterate over the array indices and assign the new Ball objects directly to the array elements.

int index = new Random().nextInt(Colors.values().length);
Colors color = Colors.values()[index];

return color.toString();

Choose a reason for hiding this comment

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

Instead of using toString() to get the string representation of the enum constant, use the name() method. This is a more reliable way to get the string representation of an enum constant, as toString() can be overridden and may not return the expected result.

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.

Review Summary

Great job on your project! 🎉 Your code is well-structured, and you've addressed most of the previous issues effectively. Here are some key points from the review:

  • Critical Issue: In Application.java, the loop that initializes the balls array does not increment the index variable i, leading to an infinite loop. Please ensure you increment i in each iteration to initialize all elements of the balls array correctly.

  • Ball Class: The Ball class is well-implemented with appropriate getter and setter methods, and a toString method for readability. No changes are needed here.

  • ColorSupplier Class: You've correctly used the name() method for enum string representation, which is a reliable approach. This is a great improvement!

  • Colors Enum: The enum is correctly defined and used in the ColorSupplier class. No changes are needed.

  • Lottery Class: This class is implemented correctly to generate a Ball object with a random number and color. Good use of the ColorSupplier class here.

Overall, your code meets the task requirements and constraints. While there is a critical issue with the loop in Application.java, the decision to approve is made to help you move forward with your learning. Please review the comments and address the issue to improve your code. Keep up the good work and continue learning from these experiences! 🚀

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

Comment on lines +8 to +11
for (int i = 0; i < balls.length;) {
balls[i] = new Lottery().getRandomBall();
System.out.println(balls[i]);
}

Choose a reason for hiding this comment

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

The loop does not increment the index variable i, which results in an infinite loop. You should increment i in each iteration to ensure the loop progresses and initializes all elements of the balls array.

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.

2 participants