Skip to content

Conversation

LynAlinka
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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();

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.

Comment on lines 9 to 10
int index = random.nextInt(Color.values().length);
return Color.values()[index];

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();

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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private Color color;
private String color;

return null;
private Random random = new Random();

public Color getRandomColor() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Color getRandomColor() {
public String getRandomColor() {


public Ball getRandomBall() {
Color color = colorSupplier.getRandomColor();
int number = random.nextInt(100) + 1;

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);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

// create three balls using class Lottery and print information about them in console
Lottery lottery = new Lottery();

for (int i = 0; i < 3; i++) {

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

Comment on lines 8 to 9
Ball ball = lottery.getRandomBall();
System.out.println(ball);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Ball ball = lottery.getRandomBall();
System.out.println(ball);
System.out.println(lottery.getRandomBall());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants