Skip to content

Commit 6d2591a

Browse files
committed
change the mistakes
1 parent 5636711 commit 6d2591a

File tree

5 files changed

+20
-21
lines changed

5 files changed

+20
-21
lines changed

src/main/java/core/basesyntax/Application.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package core.basesyntax;
22

33
public class Application {
4+
private static final int NUMBER_OF_BALLS = 3;
45
public static void main(String[] args) {
56
Lottery lottery = new Lottery();
6-
Ball[] balls = new Ball[3];
7+
Ball[] balls = new Ball[NUMBER_OF_BALLS];
78
for (int i = 0; i < 3; i++) {
89
balls[i] = lottery.getRandomBall();
910
System.out.println(balls[i].toString());

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
package core.basesyntax;
22

33
public class Ball {
4-
private String color;
4+
private Color color;
55
private int number;
6-
public void setColor(String color) {
6+
public Ball(Color color, int number){
77
this.color = color;
8-
}
9-
public void setNumber(int number) {
108
this.number = number;
119
}
1210
public String getColor() {
13-
return color;
11+
return color.toString();
1412
}
1513
public int getNumber() {
1614
return number;
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package core.basesyntax;
22

33
public enum Color {
4-
pink,
5-
blue,
6-
yellow,
7-
green,
8-
red,
9-
purple
4+
PINK,
5+
BLUE,
6+
YELLOW,
7+
GREEN,
8+
RED,
9+
PURPLE
1010
}

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

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

55
public class ColorSupplier {
6-
public String getRandomColor() {
7-
int index = new Random().nextInt(Color.values().length);
8-
return Color.values()[index].toString();
6+
private Random random;
7+
public Color getRandomColor() {
8+
int index = random.nextInt(Color.values().length);
9+
return Color.values()[index];
910
}
1011
}

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

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

55
public class Lottery {
6+
private Random random;
7+
private static final int MAX_BALL_NUMBER = 100;
68
ColorSupplier colorSupplier = new ColorSupplier();
79
public Ball getRandomBall() {
8-
Random random = new Random();
9-
int number = random.nextInt(100);
10-
String color = colorSupplier.getRandomColor();
11-
Ball ball = new Ball();
12-
ball.setColor(color);
13-
ball.setNumber(number);
10+
int number = random.nextInt(MAX_BALL_NUMBER);
11+
Color color = colorSupplier.getRandomColor();
12+
Ball ball = new Ball(color, number);
1413
return ball;
1514
}
1615
}

0 commit comments

Comments
 (0)