-
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
maked lottery task #1693
base: master
Are you sure you want to change the base?
maked lottery task #1693
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.
Hello! 😊 You've done a great job implementing the core functionality of the task, and your code is mostly on point. However, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Access Modifiers: The
Ball
class fields lack explicit access modifiers. It's important to define these to ensure encapsulation and maintainability of your code. -
Magic Numbers: In the
Lottery
class, the number100
is used directly. It's best practice to define this as a constant to improve code readability and maintainability. -
Enum String Representation: In the
ColorSupplier
class, usingtoString()
for enums can lead to unexpected results if overridden. Please usename()
instead for a more reliable approach. -
Unnecessary Instance Creation: Creating a new
ColorSupplier
instance every timegetRandomBall()
is called is inefficient. Consider creating a single instance and reusing it.
These changes are essential to ensure the code is robust and adheres to best practices. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀
✨ 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.
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
int index = new Random().nextInt(Colors.values().length); | ||
return Colors.values()[index].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()
, use the name()
method to get the string representation of the enum constants. This is a more reliable approach as toString()
can be overridden, potentially leading to unexpected results.
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 main functionality of the Application
class and addressing some of the previous review comments! 🎉 Your code is on the right track, but there are a few important areas to focus on for improvement:
-
Access Modifiers: Ensure all classes, fields, constructors, and methods have explicit access modifiers. Specifically, the
getRandomColor
method in theColorSupplier
class should have an access modifier. -
Magic Numbers: The
Lottery
class uses the number100
directly for generating random numbers. Define this as a constant to enhance readability and maintainability. -
Instance Creation: Avoid creating new instances unnecessarily. The
ColorSupplier
class should reuse a singleRandom
instance, and theLottery
class should not create a newColorSupplier
instance every timegetRandomBall()
is called. -
Static Final Constants: The
bound
variable is correctly defined as static, but it should also befinal
to indicate it's a constant. -
Initialization: The
colorSupplier
field should be initialized either in the constructor or directly in the field declaration to preventNullPointerException
.
These improvements will help you write cleaner and more efficient code. Keep up the good work, and make sure to address these issues in future iterations to enhance your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
|
||
public class Lottery { | ||
private static int bound = 100; | ||
private ColorSupplier colorSupplier; |
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 colorSupplier
field is declared but not initialized. Consider initializing it in the constructor or directly in the field declaration to avoid potential NullPointerException
when calling getRandomColor()
.
import java.util.Random; | ||
|
||
public class Lottery { | ||
private static int bound = 100; |
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 bound
variable is defined as a static field, which is good for a constant. However, it should be declared as final
to indicate that it is a constant value and should not be changed.
No description provided.