-
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
Task is done #1727
base: master
Are you sure you want to change the base?
Task is done #1727
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 submission! While your code is on the right track, there are a few critical issues that need to be addressed before it can be approved:
-
Incorrect Use of Color Class: The
Ball
class should use the customColor
enum instead ofjava.awt.Color
. This is crucial to meet the task requirements. -
Random Color and Number Generation: The
Random
object is incorrectly initialized with a seed in bothColorSupplier
andLottery
classes. Instead, userandom.nextInt()
with the appropriate bounds to generate random values correctly. -
Efficiency in ColorSupplier Usage: The
Lottery
class should reuse a single instance ofColorSupplier
rather than creating a new one each timegetRandomBall()
is called. -
Missing Main Method: A
main()
method is needed to test the functionality by creating and printing three randomBall
objects.
Please address these issues to ensure your code meets the core requirements. Keep up the good work, and I'm confident you'll get it right 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 String getRandomColor() { | ||
return null; | ||
public Color getRandomColor() { | ||
Random random = new Random(Color.values().length); |
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 Random
constructor should not take an argument. Instead, use random.nextInt(Color.values().length)
to ensure the random index is within the bounds of the Color
array.
return null; | ||
public Color getRandomColor() { | ||
Random random = new Random(Color.values().length); | ||
return Color.values()[random.nextInt()]; |
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 random.nextInt()
method should be called with an argument specifying the upper bound. Use random.nextInt(Color.values().length)
to get a valid index for the Color.values()
array.
public Ball getRandomBall(){ | ||
Ball ball = new Ball(); | ||
ball.setColor(new ColorSupplier().getRandomColor()); | ||
Random random = new Random(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 Random
constructor should not take an argument. Instead, use random.nextInt(100)
to generate a random number between 0 and 99, or specify another range if needed.
Ball ball = new Ball(); | ||
ball.setColor(new ColorSupplier().getRandomColor()); | ||
Random random = new Random(100); | ||
ball.setNumber(random.nextInt()); |
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 random.nextInt()
method should be called with an argument specifying the upper bound. Use random.nextInt(100)
to ensure the random number is within the desired range.
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.
v1
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 making significant improvements to your code! 🎉 You've successfully implemented the main
method in the Application
class and correctly used the custom Color
enum in the Ball
class. However, there are a few critical issues that need attention:
-
Random Color Generation: In the
ColorSupplier
class, ensure theRandom
object is initialized without a seed and userandom.nextInt(Color.values().length)
to select a valid color index. -
Random Number Generation: In the
Lottery
class, userandom.nextInt(101)
to generate numbers between 0 and 100 inclusive, aligning with task requirements.
These adjustments are crucial for the functionality of your code. Addressing them will enhance your understanding and help you avoid similar issues in the future. 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! ✨
Random random = new Random(Color.values().length); | ||
return Color.values()[random.nextInt()]; |
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 Random
object should not be initialized with a seed. Instead, use Random random = new Random();
and modify random.nextInt()
to random.nextInt(Color.values().length)
to ensure it selects a valid index within the bounds of the Color
enum.
Random random = new Random(); | ||
ball.setNumber(random.nextInt(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 Random
object is correctly used without a seed, and random.nextInt(100)
is appropriate for generating a random number. Ensure that this logic meets the task requirements for the range of random numbers.
No description provided.