Skip to content

Commit

Permalink
Solved jv-lottery
Browse files Browse the repository at this point in the history
  • Loading branch information
SSXcorp committed Dec 1, 2024
1 parent 98bb7f0 commit d0ae828
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery lottery = new Lottery();
for (int i = 0; i < 3; i++) {
System.out.println(lottery.getRandomBall());
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package core.basesyntax;

public class Ball {
private String color;
private Long number;

public Ball(String color, Long number) {
this.color = color;
this.number = number;
}

public Ball() {
}

public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public Long getNumber() {
return number;
}

public void setNumber(Long number) {
this.number = number;
}

@Override
public String toString() {
return "Ball{"
+ "color='" + color + '\''
+ ", number=" + number
+ '}';
}
}
10 changes: 10 additions & 0 deletions src/main/java/core/basesyntax/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package core.basesyntax;

public enum Color {
RED,
BLUE,
GREEN,
YELLOW,
ORANGE,
PURPLE
}
10 changes: 9 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package core.basesyntax;

import java.util.Random;

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

public String getRandomColor() {
return null;
return Color.values()[getRandom().nextInt(Color.values().length)].toString();
}

public Random getRandom() {
return random;
}
}
22 changes: 22 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package core.basesyntax;

import java.util.Random;

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

public String getRandomBall() {
String color = getColorSupplier().getRandomColor();
Long number = getRandom().nextLong(100);
return new Ball(color, number).toString();
}

public ColorSupplier getColorSupplier() {
return colorSupplier;
}

public Random getRandom() {
return random;
}
}

0 comments on commit d0ae828

Please sign in to comment.