Skip to content

Conversation

mkarmadev
Copy link

…ments class ColorSupplier; implements main() in Application class

…ments class ColorSupplier; implements main() in Application class
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 your code submission! 👍 It looks like you've followed the checklist thoroughly, and there are no critical issues that impact the functionality or security of your code. Remember to always consider the scope of your methods and fields, and whether they should be static or not. Keep up the good work, and continue paying attention to best practices for a clean and maintainable codebase! 😊👨‍💻

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

import java.util.Random;

public class ColorSupplier {
private static final int COLOR_COUNT = Color.values().length;

Choose a reason for hiding this comment

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

Using static fields for constants is a good practice. However, be cautious with static fields that are not constants, like random in line 7. It's better to avoid static methods and fields unless they are constants or there is a specific reason to use them.

private static final int COLOR_COUNT = Color.values().length;
private Random random = new Random();

public String getRandomColor() {

Choose a reason for hiding this comment

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

According to Java best practices, it's recommended to use access modifiers explicitly. Consider defining the access level for the getRandomColor method explicitly if you have a specific intention for package-private access level.

Comment on lines 10 to 11
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());

return color;
}

public void setColor(String color) {

Choose a reason for hiding this comment

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

remove methods that you don't use

import java.util.Random;

public class ColorSupplier {
private static final int COLOR_COUNT = Color.values().length;

Choose a reason for hiding this comment

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

Suggested change
private static final int COLOR_COUNT = Color.values().length;
private static final int COLORS = Color.values();

or your suggestion of name


public String getRandomColor() {
return null;
int colorNumber = random.nextInt(COLOR_COUNT);

Choose a reason for hiding this comment

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

Suggested change
int colorNumber = random.nextInt(COLOR_COUNT);
int colorNumber = random.nextInt(COLORS.length);

return null;
int colorNumber = random.nextInt(COLOR_COUNT);

return Color.values()[colorNumber].name();

Choose a reason for hiding this comment

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

Suggested change
return Color.values()[colorNumber].name();
return COLORS[colorNumber].name();


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

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

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.

3 participants