-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
Implement Lottery #1718
Conversation
There was a problem hiding this 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! ✨
Ball ball1 = lottery.getRandomBall(); | ||
Ball ball2 = lottery.getRandomBall(); | ||
Ball ball3 = lottery.getRandomBall(); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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'.
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.