Skip to content

feat: implement Lottery and Ball classes with random color supply#2018

Open
DanyilShkodiuk wants to merge 5 commits intomate-academy:masterfrom
DanyilShkodiuk:lottery-feature
Open

feat: implement Lottery and Ball classes with random color supply#2018
DanyilShkodiuk wants to merge 5 commits intomate-academy:masterfrom
DanyilShkodiuk:lottery-feature

Conversation

@DanyilShkodiuk
Copy link

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

  • Colors enum: Added a set of constants (RED, GREEN, BLUE, YELLOW, BROWN, WHITE, BLACK) to represent available ball colors.
  • Ball class: Created a model class with fields for color and number, including a constructor and appropriate methods.
  • ColorSupplier: Implemented logic to retrieve a random color from the Colors enum using java.util.Random.
  • Lottery: Added functionality to produce a Ball object 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.

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

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 in ColorSupplier should be an instance method, not static. [CHECKLIST ITEM #3]
  • Inefficient Object Creation: In both Lottery and ColorSupplier, a new Random object is created on every method call. Please declare Random as a private field and initialize it once. [CHECKLIST ITEM #4]
  • Magic Numbers: The numbers 3 in Application.java and 100 in Lottery.java must be declared as named constants. [CHECKLIST ITEM #9]
  • Enum Method: The toString() method was used on the enum in ColorSupplier. The requirements specify using the name() 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

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

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

Footnotes

  1. Rate AI review example

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