Skip to content
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

Implement Lottery #1703

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Implement Lottery #1703

wants to merge 7 commits into from

Conversation

MaybeTI
Copy link

@MaybeTI MaybeTI commented Nov 19, 2024

No description provided.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Let's check the common mistakes list and fix your solution by list ;)

src/main/java/core/basesyntax/Ball.java Show resolved Hide resolved
Comment on lines 4 to 5
private final Colors color;
private final int number;

Choose a reason for hiding this comment

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

Suggested change
private final Colors color;
private final int number;
private Colors color;
private int number;

@@ -0,0 +1,14 @@
package core.basesyntax;

public enum Colors {

Choose a reason for hiding this comment

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

Suggested change
public enum Colors {
public enum Color {

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Let’s check the common mistakes list again

public class ColorSupplier {
public String getRandomColor() {
return null;
public static 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 static Color getRandomColor() {
public Color getRandomColor() {

Don't use static methods in your solution (from common mistakes)

public String getRandomColor() {
return null;
public static Color getRandomColor() {
return Color.values()[new Random().nextInt(Color.values().length)];

Choose a reason for hiding this comment

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

Think about which variables should be local in the method and which should be class-level (following common mistakes)

Comment on lines 6 to 8
public static Ball getRandomBall() {
return new Ball(ColorSupplier.getRandomColor(), new Random().nextInt(101));
}

Choose a reason for hiding this comment

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

the same Also, All magic numbers in your code should be constants. (from common mistakes)

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! But fix my comments ;)


public void main(String[] args) {
for (int i = 0; i < BALL_COUNT; i++) {
System.out.println(new Lottery().getRandomBall());

Choose a reason for hiding this comment

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

in this realization, you create 3 new instances one instant is enough

Comment on lines +6 to +8
public void main(String[] args) {
for (int i = 0; i < BALL_COUNT; i++) {
System.out.println(new Lottery().getRandomBall());

Choose a reason for hiding this comment

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

Suggested change
public void main(String[] args) {
for (int i = 0; i < BALL_COUNT; i++) {
System.out.println(new Lottery().getRandomBall());
public void main(String[] args) {
Lottery lottery = new Lottery();
for (int i = 0; i < BALL_COUNT; i++) {
System.out.println(lottery.getRandomBall());

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.

Suggested change
private Random random = new Random();
private final Random random = new Random();

Comment on lines +7 to +10
private Random random = new Random();

public Ball getRandomBall() {
return new Ball(new ColorSupplier().getRandomColor(), random.nextInt(BALL_NUMBER));

Choose a reason for hiding this comment

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

Suggested change
private Random random = new Random();
public Ball getRandomBall() {
return new Ball(new ColorSupplier().getRandomColor(), random.nextInt(BALL_NUMBER));
private final Random random = new Random();
private final ColorSupplier supplier = new ColorSupplier()
public Ball getRandomBall() {
return new Ball(supplier.getRandomColor(), random.nextInt(BALL_NUMBER));

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.

2 participants