Skip to content

Commit f0d85e0

Browse files
fix review comments
1 parent f08d98f commit f0d85e0

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
package core.basesyntax;
22

33
public class Application {
4+
private static final int NUMBER_OF_BALLS = 3;
5+
46
public static void main(String[] args) {
5-
// create three balls using class Lottery and print information about them in console
67
Lottery lottery = new Lottery();
7-
Ball firstBall = lottery.getRandomBall();
8-
Ball secondBall = lottery.getRandomBall();
9-
Ball thirdBall = lottery.getRandomBall();
10-
System.out.println(firstBall.toString());
11-
System.out.println(secondBall.toString());
12-
System.out.println(thirdBall.toString());
8+
for (int i = 0; i < NUMBER_OF_BALLS; i++) {
9+
Ball ball = lottery.getRandomBall();
10+
System.out.println(ball.toString());
11+
}
1312
}
1413
}

src/main/java/core/basesyntax/Ball.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
public class Ball {
44

5-
private String colour;
5+
private String color;
66

77
private int number;
88

9-
public Ball(String colour, int number) {
10-
this.colour = colour;
9+
public Ball(String color, int number) {
10+
this.color = color;
1111
this.number = number;
1212
}
1313

1414
@Override
1515
public String toString() {
16-
return "Ball colour is " + colour
16+
return "Ball colour is " + color
1717
+ " number is " + number;
1818
}
1919
}

src/main/java/core/basesyntax/ColorSupplier.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
import java.util.Random;
44

55
public class ColorSupplier {
6+
private final Random random = new Random();
7+
68
public String getRandomColor() {
7-
int index = new Random().nextInt(Colours.values().length);
8-
Colours colour = Colours.values()[index];
9-
return colour.toString();
9+
return Colors.values()[random.nextInt(Colors.values().length)].name();
1010
}
1111
}

src/main/java/core/basesyntax/Colours.java renamed to src/main/java/core/basesyntax/Colors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package core.basesyntax;
22

3-
public enum Colours {
3+
public enum Colors {
44
PINK,
55
PURPLE,
66
BLUE,

src/main/java/core/basesyntax/Lottery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
import java.util.Random;
44

55
public class Lottery {
6+
private static final int MAX_NUMBER = 101;
67
private final ColorSupplier colorSupplier = new ColorSupplier();
8+
private final Random random = new Random();
79

810
public Ball getRandomBall() {
9-
String randomColour = colorSupplier.getRandomColor();
10-
int randomNumber = new Random().nextInt(100);
11-
return new Ball(randomColour, randomNumber);
11+
return new Ball(colorSupplier.getRandomColor(), random.nextInt(MAX_NUMBER));
1212
}
1313
}

0 commit comments

Comments
 (0)