Skip to content

Commit

Permalink
fixed some mistakes 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Ann1120-ua committed Nov 26, 2024
1 parent ceb4e27 commit 9d74059
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package core.basesyntax;

public class Application {
private static final int NUMBER_OF_BALLS = 3;

public static void main(String[] args) {

Lottery lottery = new Lottery();

final int numberOfBalls = 3;

for (int i = 0; i < numberOfBalls; i++) {
for (int i = 0; i < NUMBER_OF_BALLS; i++) {
Ball ball = lottery.getRandomBall();
System.out.println(ball);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public class Ball {
private final Color color;
private final int number;

public Ball(String color, int number) {
this.color = Color.valueOf(color);
public Ball(Color color, int number) {
this.color = color;
this.number = number;
}

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
import java.util.Random;

public class ColorSupplier {
private Random random = new Random();

public String getRandomColor() {
private final Random random = new Random();

public Color getRandomColor() {
Color[] colors = Color.values();
int randomIndex = random.nextInt(colors.length);

return colors[randomIndex].name();
int index = random.nextInt(colors.length);
return colors[index];
}
}
10 changes: 5 additions & 5 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

public class Lottery {

private final int maxBallCount = 100;
private Random random = new Random();
private ColorSupplier colorSupplier = new ColorSupplier();
private final static int MAX_BALL_COUNT = 100;
private final Random random = new Random();
private final ColorSupplier colorSupplier = new ColorSupplier();

public Ball getRandomBall() {
String color = colorSupplier.getRandomColor();
int number = random.nextInt(maxBallCount) + 1;
Color color = colorSupplier.getRandomColor();
int number = random.nextInt(MAX_BALL_COUNT) + 1;
return new Ball(color, number);
}
}

0 comments on commit 9d74059

Please sign in to comment.