diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java index 42ed4ef86..5540f9d9e 100644 --- a/src/main/java/core/basesyntax/Application.java +++ b/src/main/java/core/basesyntax/Application.java @@ -3,5 +3,10 @@ public class Application { public static void main(String[] args) { // create three balls using class Lottery and print information about them in console + for (int i = 0; i < 3; i++) { + Lottery lottery = new Lottery(); + Ball ball = lottery.getRandomBall(); + System.out.println(ball); + } } } diff --git a/src/main/java/core/basesyntax/Ball.java b/src/main/java/core/basesyntax/Ball.java new file mode 100644 index 000000000..5c9e3e0a0 --- /dev/null +++ b/src/main/java/core/basesyntax/Ball.java @@ -0,0 +1,27 @@ +package core.basesyntax; + +public class Ball { + private Colors color; + private int number; + + public void setColor(Colors color) { + this.color = color; + } + + public String getColor() { + return this.color.toString(); + } + + public void setNumber(int number) { + this.number = number; + } + + public int getNumber() { + return this.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..ce64cb674 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -1,7 +1,11 @@ package core.basesyntax; +import java.util.Random; + public class ColorSupplier { - public String getRandomColor() { - return null; + public Colors getRandomColor() { + Random random = new Random(); + int index = random.nextInt(Colors.values().length); + return Colors.values()[index]; } } diff --git a/src/main/java/core/basesyntax/Colors.java b/src/main/java/core/basesyntax/Colors.java new file mode 100644 index 000000000..17a960e2c --- /dev/null +++ b/src/main/java/core/basesyntax/Colors.java @@ -0,0 +1,10 @@ +package core.basesyntax; + +public enum Colors { + RED, + BLUE, + GREEN, + YELLOW, + ORANGE, + BLACK +} diff --git a/src/main/java/core/basesyntax/Lottery.java b/src/main/java/core/basesyntax/Lottery.java new file mode 100644 index 000000000..9ae19edef --- /dev/null +++ b/src/main/java/core/basesyntax/Lottery.java @@ -0,0 +1,15 @@ +package core.basesyntax; + +import java.util.Random; + +public class Lottery { + public Ball getRandomBall() { + Ball ball = new Ball(); + ColorSupplier colorSupplier = new ColorSupplier(); // Create a ColorSupplier object + Colors randomColor = colorSupplier.getRandomColor(); + ball.setColor(randomColor); + int randomValue = new Random().nextInt(100); + ball.setNumber(randomValue); + return ball; + } +}