Skip to content

Commit

Permalink
created a lottery about balls with random number and color
Browse files Browse the repository at this point in the history
  • Loading branch information
sokoligor29 committed Dec 12, 2024
1 parent 98bb7f0 commit ca859f3
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
7 changes: 6 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,11 @@

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 ++) {
Ball ball = lottery.getRandomBall();
System.out.println(ball);
}
}
}
19 changes: 19 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package core.basesyntax;

public class Ball {
private final String color;
private final int number;

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

@Override
public String toString() {
return "Ball{" +
"color='" + color + '\'' +
", number=" + number +
'}';
}
}
6 changes: 5 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package core.basesyntax;

import java.util.Random;

public class ColorSupplier {
public String getRandomColor() {
return null;
int index = new Random().nextInt(Colors.values().length);
Colors color = Colors.values()[index];
return color.toString();
}
}
12 changes: 12 additions & 0 deletions src/main/java/core/basesyntax/Colors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package core.basesyntax;

public enum Colors {
YELLOW,
BLUE,
PINK,
PURPLE,
GREEN,
RED,
WHITE,
BROWN
}
14 changes: 14 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package core.basesyntax;

import java.util.Random;

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

public Ball getRandomBall() {
String randomColor = colorSupplier.getRandomColor();
int randomNumber = random.nextInt(101);
return new Ball(randomColor, randomNumber);
}
}

0 comments on commit ca859f3

Please sign in to comment.