Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package core.basesyntax;

public class Application {
private static final int NUMBER_OF_BALL = 3;

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 < NUMBER_OF_BALL; i++) {
System.out.println(lottery.getRandomBall());
}
}
}
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 String color;
private int number;

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

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

public enum Color {
GREEN,
RED,
BLUE,
WHITE,
BLACK,
YELLOW,
BROWN,
GREY,
VIOLET,
ORANGE
}
9 changes: 8 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package core.basesyntax;

import java.util.Random;

public class ColorSupplier {
private static final Color[] COLORS = Color.values();
private Random random = new Random();

public String getRandomColor() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to Java best practices, it's recommended to use access modifiers explicitly. Consider defining the access level for the getRandomColor method explicitly if you have a specific intention for package-private access level.

return null;
int colorNumber = random.nextInt(COLORS.length);

return COLORS[colorNumber].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 BOUND_NUMBER = 100;
private Random random = new Random();
private ColorSupplier colorSupplier = new ColorSupplier();

public Ball getRandomBall() {
String color = colorSupplier.getRandomColor();
int number = random.nextInt(BOUND_NUMBER);
return new Ball(color, number);
}
}
Loading