-
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
solution #1753
base: master
Are you sure you want to change the base?
solution #1753
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, and your code mostly aligns with the task requirements. However, there are a few important improvements needed before we can approve the pull request:
-
Use a Loop for Object Creation: In the
Application.java
file, instead of manually creating three instances of theLottery
class, you should use a loop to create and print the results. This will make your code more concise and easier to maintain. -
Avoid Multiple Instances: You don't need to create multiple instances of the
Lottery
class. You can create one instance and use it to generate all the random balls. -
Magic Numbers: Replace the magic number
100
in theLottery
class with a constant for better readability and maintainability. -
Optimize Object Creation: In the
Lottery
class, avoid creating a newColorSupplier
instance each timegetRandomBall()
is called. Instead, create a single instance and reuse it.
These changes will enhance the efficiency and readability of your code. Keep up the great work, and feel free to reach out if you have any questions! 🚀
✨ 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.
Lottery l1 = new Lottery(); | ||
System.out.println(l1.getRandomBall()); | ||
|
||
Lottery l2 = new Lottery(); | ||
System.out.println(l2.getRandomBall()); | ||
|
||
Lottery l3 = new Lottery(); | ||
System.out.println(l3.getRandomBall()); |
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 creating three separate instances of Lottery
and calling getRandomBall()
on each, consider using a loop to achieve the same result. This approach is recommended in the checklist: 'Use for loop for creating several objects of the same class'.
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 task requirements! 🎉 Your code is well-structured, and you've made good progress. Here are a few suggestions to enhance your code further:
-
Lottery Class: Consider creating a single instance of
Random
andColorSupplier
as class members to avoid creating new instances each timegetRandomBall()
is called. This will improve efficiency. -
Application Class: Instead of creating a new
Lottery
instance in each loop iteration, create one outside the loop and reuse it. -
Magic Numbers: Replace the number
100
in theLottery
class with a constant for better readability.
These improvements will help you write more efficient and maintainable code. Keep up the good work and continue learning from these suggestions! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
for (int i = 0; i < 3; i++) { | ||
System.out.println(new Lottery().getRandomBall()); |
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.
Currently, a new instance of the Lottery
class is created in each iteration of the loop. To optimize this, consider creating a single instance of the Lottery
class outside the loop and reusing it. This will improve the efficiency of your code.
public Colors getRandomColor() { | ||
int index = new Random().nextInt(Colors.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.
To improve efficiency, consider creating a single instance of Random
as a class member and reusing it in the getRandomColor
method. This avoids creating a new Random
object each time the method is called.
public class Lottery { | ||
public Ball getRandomBall() { | ||
Ball newBall = new Ball(); | ||
newBall.setNumber(new 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.
Consider creating a single instance of Random
as a class member and reusing it in the getRandomBall
method. This avoids creating a new Random
object each time the method is called.
public Ball getRandomBall() { | ||
Ball newBall = new Ball(); | ||
newBall.setNumber(new Random().nextInt(100)); | ||
newBall.setColor(new 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.
Instead of creating a new ColorSupplier
instance each time getRandomBall()
is called, consider creating a single instance of ColorSupplier
as a class member and reusing it. This will improve the efficiency of your code.
No description provided.