-
Notifications
You must be signed in to change notification settings - Fork 1.5k
created classes,enum and solved the task #1579
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?
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.
Great job on following the checklist guidelines and ensuring your code is clean and well-structured! 👍 Just a couple of tips for future improvements: remember to reuse arrays created by methods like Color.values()
by storing them in a local variable if you're going to use them multiple times. Also, for better performance and resource management, consider making the Random
instance a static constant if your class is used frequently. Keep up the good work! 💻🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
private Random random = new Random(); |
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 moving the 'Random' instance to be a class-level constant, since it does not need to be instantiated multiple times if the 'ColorSupplier' class is used multiple times.
int index = random.nextInt(Color.values().length); | ||
return Color.values()[index]; |
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.
You're calling 'Color.values()' twice which creates a new array each time it's called. It's better to store it in a local variable and reuse it.
// create three balls using class Lottery and print information about them in console | ||
Lottery lottery = new Lottery(); | ||
|
||
Ball ball1 = 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.
Use for loop
package core.basesyntax; | ||
|
||
public class Ball { | ||
private Color 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.
private Color color; | |
private String color; |
return null; | ||
private Random random = new Random(); | ||
|
||
public Color 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.
public Color getRandomColor() { | |
public String getRandomColor() { |
|
||
public Ball getRandomBall() { | ||
Color color = colorSupplier.getRandomColor(); | ||
int number = random.nextInt(100) + 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.
100 is a magic number, create constant
int number = random.nextInt(100) + 1; | ||
return new Ball(color, number); | ||
} | ||
|
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.
// create three balls using class Lottery and print information about them in console | ||
Lottery lottery = new Lottery(); | ||
|
||
for (int i = 0; i < 3; 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.
3 is a magic number, create constant
Ball ball = 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.
Ball ball = lottery.getRandomBall(); | |
System.out.println(ball); | |
System.out.println(lottery.getRandomBall()); |
No description provided.