-
Notifications
You must be signed in to change notification settings - Fork 1.5k
implement lottery ball generation logic #1891
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
base: master
Are you sure you want to change the base?
implement lottery ball generation logic #1891
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.
Review Summary
Thank you for your submission! You're on the right track with your class structure and use of enums, but there are a few critical issues that must be fixed before your code meets all the requirements:
-
Use of String instead of Color enum
- The
Ball
class should use theColor
enum for itscolor
field and constructor parameter, not aString
. This ensures type safety and matches the assignment requirements. - The
ColorSupplier.getRandomColor()
method should return aColor
value, not aString
. Update its return type and logic accordingly. - Update the
Lottery.getRandomBall()
method to use the enum type throughout (pass theColor
toBall
).
- The
-
Magic Numbers Not Defined as Constants
- In
Application.java
, the number3
(used for the array size and loop) should be defined as a constant, e.g.,private static final int BALLS_COUNT = 3;
, following Java constant naming conventions.
- In
-
Possible Incorrect Ball Number Range
- In
Lottery.java
, the random number generation currently allows numbers from 0 to 100 inclusive. If the intended range is 1-100, you should userandom.nextInt(MAX_BALL_NUMBER) + 1
to ensure numbers are between 1 and 100.
- In
-
Redundant Empty Lines After Class Declarations
- There are unnecessary empty lines after class declarations in several files (
Application.java
,Ball.java
,Color.java
,ColorSupplier.java
,Lottery.java
). Please remove these to comply with the style requirements.
- There are unnecessary empty lines after class declarations in several files (
Next Steps:
- Update your code to use the
Color
enum everywhere a color is needed. - Replace all magic numbers with properly named constants.
- Adjust the random number logic if needed.
- Clean up redundant empty lines.
Once you've made these changes, your code will be much more robust and fully compliant with the assignment requirements. Keep up the good work—you're almost there!
✨ 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
@@ -2,6 +2,15 @@ | |||
|
|||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery lottery = new Lottery(); | |||
Ball[] balls = new Ball[3]; |
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.
This violates checklist item: "All magic numbers (like 100, 3) must be defined as constants, following Java constant naming conventions." You should define a constant (e.g., private static final int BALLS_COUNT = 3;
) and use it here instead of the literal 3.
@@ -2,6 +2,15 @@ | |||
|
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.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration.
package core.basesyntax; | ||
|
||
public class Ball { | ||
private final String color; |
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.
This violates the requirement: "Create a Ball class with fields: color and number." and "Create an enum with different colors." The color field should be of the enum type (e.g., Color), not String. The constructor should also accept the enum type, not a String.
@@ -0,0 +1,17 @@ | |||
package core.basesyntax; | |||
|
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.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration.
@@ -0,0 +1,9 @@ | |||
package core.basesyntax; | |||
|
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.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the package declaration.
public class ColorSupplier { | ||
private final Random random = new Random(); | ||
|
||
public String getRandomColor() { |
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.
This violates the requirement: "Implement a ColorSupplier class with a getRandomColor() method that returns a random color from the enum using the Random class." The method should return the Color enum type, not a String. Change the return type to Color and return the enum value directly.
@@ -1,7 +1,11 @@ | |||
package core.basesyntax; | |||
|
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.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration.
|
||
public Ball getRandomBall() { | ||
return new Ball( | ||
this.colorSupplier.getRandomColor(), |
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.
This violates the requirement: "The Ball class must have a constructor that sets both color and number." and "Create an enum with different colors." The Ball constructor should accept the Color enum, not a String. Ensure that getRandomColor() returns Color and Ball accepts Color as its color field.
public Ball getRandomBall() { | ||
return new Ball( | ||
this.colorSupplier.getRandomColor(), | ||
this.random.nextInt(MAX_BALL_NUMBER + 1) |
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.
This may violate the requirement: "The maximum possible number for the ball is 100 (i.e., numbers should be in the range 0 to 99 or 1 to 100, clarify in implementation)." If the intended range is 1-100, you should use random.nextInt(MAX_BALL_NUMBER) + 1
instead of random.nextInt(MAX_BALL_NUMBER + 1)
. Please clarify and adjust accordingly.
@@ -0,0 +1,17 @@ | |||
package core.basesyntax; | |||
|
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.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration.
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.
Review Summary
All core requirements for the lottery application are fully met. Your code correctly implements the required classes (Ball
, Color
, ColorSupplier
, Lottery
, and Application
), uses enums and constants appropriately, and follows Java conventions and best practices. There are no critical or blocking issues—everything functions as expected, and your code is clean and well-structured. Excellent job! Keep up the great work.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.