Skip to content

Commit

Permalink
Created program that return balls with a random color and random number
Browse files Browse the repository at this point in the history
  • Loading branch information
Your_Name Your_Surname committed Dec 18, 2024
1 parent 98bb7f0 commit c9c03b6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 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
Ball ball1 = new Lottery().getRandomBall();
Ball ball2 = new Lottery().getRandomBall();
Ball ball3 = new Lottery().getRandomBall();
System.out.println(ball1 + ", " + ball2 + ", " + ball3);
}
}
14 changes: 14 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package core.basesyntax;

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

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

import java.util.Random;

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

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

import java.util.Random;

public class Lottery {
Ball getRandomBall() {
Ball ball = new Ball();
ball.color = String.valueOf(new ColorSupplier().getRandomColor());
ball.number = new Random().nextInt(100);
return ball;
}
}

0 comments on commit c9c03b6

Please sign in to comment.