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

Task is done #1727

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

Task is done #1727

wants to merge 6 commits into from

Conversation

PiotrHic
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 submission! While your code is on the right track, there are a few critical issues that need to be addressed before it can be approved:

  1. Incorrect Use of Color Class: The Ball class should use the custom Color enum instead of java.awt.Color. This is crucial to meet the task requirements.

  2. Random Color and Number Generation: The Random object is incorrectly initialized with a seed in both ColorSupplier and Lottery classes. Instead, use random.nextInt() with the appropriate bounds to generate random values correctly.

  3. Efficiency in ColorSupplier Usage: The Lottery class should reuse a single instance of ColorSupplier rather than creating a new one each time getRandomBall() is called.

  4. Missing Main Method: A main() method is needed to test the functionality by creating and printing three random Ball objects.

Please address these issues to ensure your code meets the core requirements. Keep up the good work, and I'm confident you'll get it right 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.

public String getRandomColor() {
return null;
public Color getRandomColor() {
Random random = new Random(Color.values().length);

Choose a reason for hiding this comment

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

The Random constructor should not take an argument. Instead, use random.nextInt(Color.values().length) to ensure the random index is within the bounds of the Color array.

return null;
public Color getRandomColor() {
Random random = new Random(Color.values().length);
return Color.values()[random.nextInt()];

Choose a reason for hiding this comment

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

The random.nextInt() method should be called with an argument specifying the upper bound. Use random.nextInt(Color.values().length) to get a valid index for the Color.values() array.

public Ball getRandomBall(){
Ball ball = new Ball();
ball.setColor(new ColorSupplier().getRandomColor());
Random random = new Random(100);

Choose a reason for hiding this comment

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

The Random constructor should not take an argument. Instead, use random.nextInt(100) to generate a random number between 0 and 99, or specify another range if needed.

Ball ball = new Ball();
ball.setColor(new ColorSupplier().getRandomColor());
Random random = new Random(100);
ball.setNumber(random.nextInt());

Choose a reason for hiding this comment

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

The random.nextInt() method should be called with an argument specifying the upper bound. Use random.nextInt(100) to ensure the random number is within the desired range.

Copy link
Author

@PiotrHic PiotrHic left a comment

Choose a reason for hiding this comment

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

v1

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 making significant improvements to your code! 🎉 You've successfully implemented the main method in the Application class and correctly used the custom Color enum in the Ball class. However, there are a few critical issues that need attention:

  1. Random Color Generation: In the ColorSupplier class, ensure the Random object is initialized without a seed and use random.nextInt(Color.values().length) to select a valid color index.

  2. Random Number Generation: In the Lottery class, use random.nextInt(101) to generate numbers between 0 and 100 inclusive, aligning with task requirements.

These adjustments are crucial for the functionality of your code. Addressing them will enhance your understanding and help you avoid similar issues in the future. 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 +7 to +8
Random random = new Random(Color.values().length);
return Color.values()[random.nextInt()];

Choose a reason for hiding this comment

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

The Random object should not be initialized with a seed. Instead, use Random random = new Random(); and modify random.nextInt() to random.nextInt(Color.values().length) to ensure it selects a valid index within the bounds of the Color enum.

Comment on lines +12 to +13
Random random = new Random();
ball.setNumber(random.nextInt(100));

Choose a reason for hiding this comment

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

The Random object is correctly used without a seed, and random.nextInt(100) is appropriate for generating a random number. Ensure that this logic meets the task requirements for the range of random numbers.

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