diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java index 42ed4ef86..eb278ff27 100644 --- a/src/main/java/core/basesyntax/Application.java +++ b/src/main/java/core/basesyntax/Application.java @@ -1,7 +1,16 @@ package core.basesyntax; public class Application { + private static final int BALLS_COUNT = 3; + public static void main(String[] args) { // create three balls using class Lottery and print information about them in console + Lottery lottery = new Lottery(); + Ball[] balls = new Ball[BALLS_COUNT]; + + for (int i = 0; i < balls.length; i++) { + balls[i] = lottery.getRandomBall(); + System.out.println(balls[i]); + } } } diff --git a/src/main/java/core/basesyntax/Ball.java b/src/main/java/core/basesyntax/Ball.java new file mode 100644 index 000000000..fed443ffa --- /dev/null +++ b/src/main/java/core/basesyntax/Ball.java @@ -0,0 +1,29 @@ +package core.basesyntax; + +public class Ball { + private String color; + private int number; + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + + public int getNumber() { + return number; + } + + public void setNumber(int number) { + this.number = number; + } + + @Override + public String toString() { + return "Ball{" + + "color='" + color + '\'' + + ", number=" + number + '}'; + } +} diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index 25e8b23b1..0313c7571 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -1,7 +1,13 @@ package core.basesyntax; +import java.util.Random; + public class ColorSupplier { + private final Random random = new Random(); + public String getRandomColor() { - return null; + int index = random.nextInt(Colors.values().length); + Colors color = Colors.values()[index]; + return color.name(); } } diff --git a/src/main/java/core/basesyntax/Colors.java b/src/main/java/core/basesyntax/Colors.java new file mode 100644 index 000000000..cd1782d39 --- /dev/null +++ b/src/main/java/core/basesyntax/Colors.java @@ -0,0 +1,9 @@ +package core.basesyntax; + +public enum Colors { + RED, + PINK, + BLUE, + YELLOW, + GREEN +} diff --git a/src/main/java/core/basesyntax/Lottery.java b/src/main/java/core/basesyntax/Lottery.java new file mode 100644 index 000000000..8c7b40789 --- /dev/null +++ b/src/main/java/core/basesyntax/Lottery.java @@ -0,0 +1,16 @@ +package core.basesyntax; + +import java.util.Random; + +public class Lottery { + private static final int MAXIMUM_NUMBER = 100; + private final Random random = new Random(); + private final ColorSupplier colorSupplier = new ColorSupplier(); + + public Ball getRandomBall() { + Ball ball = new Ball(); + ball.setColor(colorSupplier.getRandomColor()); + ball.setNumber(random.nextInt(MAXIMUM_NUMBER)); + return ball; + } +}