feat: implement Lottery and Ball classes with random color supply#2018
feat: implement Lottery and Ball classes with random color supply#2018DanyilShkodiuk wants to merge 5 commits intomate-academy:masterfrom
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Hello! Your solution correctly implements the core logic for the lottery, which is a great start. However, several changes are required to align with the project's checklist, which is a mandatory part of the task.
Please address the following points:
- Static Methods: The
getRandomColor()method inColorSuppliershould be an instance method, notstatic. [CHECKLIST ITEM #3] - Inefficient Object Creation: In both
LotteryandColorSupplier, a newRandomobject is created on every method call. Please declareRandomas a private field and initialize it once. [CHECKLIST ITEM #4] - Magic Numbers: The numbers
3inApplication.javaand100inLottery.javamust be declared as named constants. [CHECKLIST ITEM #9] - Enum Method: The
toString()method was used on the enum inColorSupplier. The requirements specify using thename()method instead. [CHECKLIST ITEM #10]
Once these issues are resolved, your solution will be in great shape. Keep up the good work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on addressing the previous feedback! Your code is very close to being perfect.
There is just one small but important issue remaining in ColorSupplier.java. You have correctly declared a Random instance as a class-level field, but inside the getRandomColor() method, you are creating a new local Random object. This local variable "shadows" the class field, which means the class field is never used, and a new object is inefficiently created on every method call.
To fix this, please remove the line Random random = new Random(); from the getRandomColor() method. This will ensure you are using the single Random instance defined for the class, which satisfies the requirement. [CHECKLIST ITEM #4]
After this change, your solution will be ready for approval. You're doing great!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work addressing the feedback on the Random object! Your solution is now correct and much more efficient. I am approving your submission to help you keep moving forward.
As a final point for improvement, take a look at ColorSupplier.java and Lottery.java. In both files, you can make the code more concise by removing the temporary variables (value, index, randomInt, color) and returning the new object directly in a single line. This is a common practice for cleaner code and aligns with our checklist recommendation to avoid temporary variables when possible [CHECKLIST ITEM #2].
This is just a stylistic tip to keep in mind for the future. You've done a great job on this task!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Description
Implemented the core logic for a lottery system that generates random lottery balls. Each ball is assigned a specific color from a predefined list and a random number between 1 and 100.
Key Changes
Colorsenum: Added a set of constants (RED, GREEN, BLUE, YELLOW, BROWN, WHITE, BLACK) to represent available ball colors.Ballclass: Created a model class with fields forcolorandnumber, including a constructor and appropriate methods.ColorSupplier: Implemented logic to retrieve a random color from theColorsenum usingjava.util.Random.Lottery: Added functionality to produce aBallobject by combining a random color and a random integer (up to 100).Application: Updated the entry point to simulate a lottery draw by printing 3 random balls to the console.