Skip to content

Commit

Permalink
Created ENUM, Ball, Color, Lottery classes. Implemented methods in th…
Browse files Browse the repository at this point in the history
…em according to the given task. Tested the program using the Main class.
  • Loading branch information
Jacalius committed Nov 21, 2024
1 parent 98bb7f0 commit 224071a
Show file tree
Hide file tree
Showing 5 changed files with 53 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 randomBall = lottery.getRandomBall();
System.out.println(randomBall);
}
}
}
16 changes: 16 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package core.basesyntax;

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

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

@Override
public String toString() {
return "Return Ball with number:" + number + " and " + color + " colore";
}
}
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 {
BLACK,
WHITE,
GREEN,
YELLOU,
RED,
BLUE
}
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

import java.util.Random;

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

public String getRandomColor() {
return null;
int index = random.nextInt(Color.values().length);
return Color.values()[index].name();
}
}
15 changes: 15 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package core.basesyntax;

import java.util.Random;

public class Lottery {
private static final int MAXIMUM_NUMBER = 100;
private Random random = new Random();
private ColorSupplier colorSupplier = new ColorSupplier();

public Ball getRandomBall() {
String color = colorSupplier.getRandomColor();
int ballNumber = random.nextInt(MAXIMUM_NUMBER) + 1;
return new Ball(color, ballNumber);
}
}

0 comments on commit 224071a

Please sign in to comment.