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
7 changes: 6 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

public class Application {
public static final int ballAmount = 3;

Choose a reason for hiding this comment

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


public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console

for (int i = 0; i < ballAmount; i++) {
System.out.println(new Lottery().getRandomBall());
}
}
}
22 changes: 22 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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
+ '}';
}
}
8 changes: 6 additions & 2 deletions 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;
public static String getRandomColor() {

Choose a reason for hiding this comment

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

Suggested change
public static String getRandomColor() {
public String getRandomColor() {

ColorsEnum [] colors = ColorsEnum.values();
int index = new Random().nextInt(colors.length);
return colors[index].toString();

Choose a reason for hiding this comment

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

}
}
9 changes: 9 additions & 0 deletions src/main/java/core/basesyntax/ColorsEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package core.basesyntax;

public enum ColorsEnum {

Choose a reason for hiding this comment

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

Suggested change
public enum ColorsEnum {
public enum Color {

RED,
BLUE,
GREEN,
YELLOW,
VIOLET,
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax;

import java.util.Random;

public class Lottery {
public static final int NumberBound = 100;

Choose a reason for hiding this comment

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

same comment about constant


public Ball getRandomBall() {
String randomColor = ColorSupplier.getRandomColor();
int randomNumber = new Random().nextInt(NumberBound);

Choose a reason for hiding this comment

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

return new Ball(randomColor, randomNumber);
}
}