-
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
add getRandomColor and getRandomBall foo #1729
base: master
Are you sure you want to change the base?
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.
Thank you for your hard work on this Pull Request! 😊 While your solution is almost there, there are a couple of critical issues that need to be addressed before we can approve it:
-
Ball Array Initialization: In the
Application
class, the enhanced for-loop does not correctly update theballs
array with the newBall
objects. This is a critical issue as it affects the core functionality of storingBall
objects. Please use a traditional for-loop to iterate over the array indices and assign the newBall
objects directly to the array elements. -
Enum String Representation: In the
ColorSupplier
class, usingtoString()
to get the string representation of the enum constant is not recommended. Please switch to using thename()
method for a more reliable result.
Once these issues are resolved, your code will be in great shape! Keep up the good work, and don't hesitate to reach out if you have any questions or need further assistance. 🌟
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
for (Ball ball: balls) { | ||
ball = new Lottery().getRandomBall(); | ||
System.out.println(ball); | ||
} |
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.
The enhanced for-loop does not update the balls
array with the new Ball
objects. Instead, it assigns the new Ball
to the ball
variable, which is a copy of the array element. To fix this, use a traditional for-loop to iterate over the array indices and assign the new Ball
objects directly to the array elements.
int index = new Random().nextInt(Colors.values().length); | ||
Colors color = Colors.values()[index]; | ||
|
||
return color.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 a more reliable way to get the string representation of an enum constant, as toString()
can be overridden and may not return the expected result.
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
Great job on your project! 🎉 Your code is well-structured, and you've addressed most of the previous issues effectively. Here are some key points from the review:
-
Critical Issue: In
Application.java
, the loop that initializes theballs
array does not increment the index variablei
, leading to an infinite loop. Please ensure you incrementi
in each iteration to initialize all elements of theballs
array correctly. -
Ball Class: The
Ball
class is well-implemented with appropriate getter and setter methods, and atoString
method for readability. No changes are needed here. -
ColorSupplier Class: You've correctly used the
name()
method for enum string representation, which is a reliable approach. This is a great improvement! -
Colors Enum: The enum is correctly defined and used in the
ColorSupplier
class. No changes are needed. -
Lottery Class: This class is implemented correctly to generate a
Ball
object with a random number and color. Good use of theColorSupplier
class here.
Overall, your code meets the task requirements and constraints. While there is a critical issue with the loop in Application.java
, the decision to approve is made to help you move forward with your learning. Please review the comments and address the issue to improve your code. Keep up the good work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
for (int i = 0; i < balls.length;) { | ||
balls[i] = new Lottery().getRandomBall(); | ||
System.out.println(balls[i]); | ||
} |
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.
The loop does not increment the index variable i
, which results in an infinite loop. You should increment i
in each iteration to ensure the loop progresses and initializes all elements of the balls
array.
No description provided.