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

Implement Lottery #1718

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

Implement Lottery #1718

wants to merge 7 commits into from

Conversation

euulu
Copy link

@euulu euulu commented Dec 11, 2024

Create a Ball class with the following fields: color and number and override the toString() method. Create an enum with different colors. Implement method getRandomColor() in class ColorSupplier. This method should return a random color, based on the enum values. Create a Lottery class with the getRandomBall() method, which will return the ball. This method should create a ball with a random color and a random number (the maximum possible number should be 100) and return this ball from the method.
In the main() method create three balls using the getRandomBall() method from the Lottery class. And print information about them in the console.

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 implementing the task requirements! 🎉 While there are a couple of minor improvements suggested, such as using a loop to create multiple Ball objects and using name() instead of toString() for enum constants, these do not impact the core functionality of your code. Keep up the good work and consider these suggestions for future enhancements! 😊

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

Comment on lines 7 to 9
Ball ball1 = lottery.getRandomBall();
Ball ball2 = lottery.getRandomBall();
Ball ball3 = lottery.getRandomBall();

Choose a reason for hiding this comment

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

According to the checklist, you should use a loop for creating several objects of the same class. Consider using a loop to create the three Ball objects instead of creating each one individually. This will make your code more concise and easier to maintain.

return null;
Random random = new Random();
int randomNumber = random.nextInt(Colors.values().length);
return Colors.values()[randomNumber].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 recommended to avoid potential issues if toString() is overridden in the future. Refer to the checklist: 'Use name() for getting String representation of enum constants'.

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