Skip to content

Commit

Permalink
fixed common mistakes mentioned in README:
Browse files Browse the repository at this point in the history
-added constants
-added for loop
-added class-level variables
-changes static method
  • Loading branch information
Manko Khristi committed Dec 1, 2024
1 parent 3337ecc commit 4c6778f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Application {
public static void main(String[] args) {
System.out.println(Lottery.getRandomBall());
System.out.println(Lottery.getRandomBall());
System.out.println(Lottery.getRandomBall());
for (int i = 0; i < 3; i++) {
System.out.println(Lottery.getRandomBall());
}
}
}
8 changes: 6 additions & 2 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
import java.util.Random;

public class ColorSupplier {
public static Color getRandomColor() {
return Color.values()[new Random().nextInt(6)];
private static final int COLOR_ENUM_SIZE = Color.values().length;

private static final Random random = new Random();

public Color getRandomColor() {
return Color.values()[random.nextInt(COLOR_ENUM_SIZE)];
}
}
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
import java.util.Random;

public class Lottery {
private static final int MAX_NUMBER = 100;

private static final ColorSupplier colorSupplier = new ColorSupplier();
private static final Random random = new Random();

public static Ball getRandomBall() {
return new Ball(new Random().nextInt(101), ColorSupplier.getRandomColor());
return new Ball(random.nextInt(MAX_NUMBER + 1), colorSupplier.getRandomColor());
}
}

0 comments on commit 4c6778f

Please sign in to comment.