Skip to content

Commit

Permalink
fixed hometask
Browse files Browse the repository at this point in the history
  • Loading branch information
163onmyneck committed Nov 16, 2023
1 parent 3ec309d commit 9c5273f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 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) {
Lottery[] lotteries = {new Lottery(), new Lottery(), new Lottery()};
for (Lottery lottery : lotteries) {
Lottery lottery = new Lottery();
for (int i = 0; i < 3; i++) {
System.out.println(lottery.getRandomBall());
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package core.basesyntax;

public class Ball {
private static final int MAX_NUMBER = 100;
private String color;
private int number;

Expand All @@ -9,6 +10,10 @@ public Ball(String color, int number) {
this.number = number;
}

public static int getMaxNumber() {
return MAX_NUMBER;
}

@Override
public String toString() {
return "{Color: " + color + ", number: " + number + "}";
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

public class Lottery {
public Ball getRandomBall() {
int randomNumber = new Random().nextInt(100);
return new Ball(new ColorSupplier().getRandomColor(), randomNumber);
int maxNumber = Ball.getMaxNumber();
Random random = new Random();
ColorSupplier colorSupplier = new ColorSupplier();
int randomNumber = random.nextInt(maxNumber);
return new Ball(colorSupplier.getRandomColor(), randomNumber);
}
}

0 comments on commit 9c5273f

Please sign in to comment.