File tree Expand file tree Collapse file tree 4 files changed +11
-14
lines changed
src/main/java/core/basesyntax Expand file tree Collapse file tree 4 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -4,12 +4,9 @@ public class Application {
4
4
public static void main (String [] args ) {
5
5
Lottery lottery = new Lottery ();
6
6
7
- Ball ball1 = lottery .getRandomBall ();
8
- Ball ball2 = lottery .getRandomBall ();
9
- Ball ball3 = lottery .getRandomBall ();
10
-
11
- System .out .println (ball1 );
12
- System .out .println (ball2 );
13
- System .out .println (ball3 );
7
+ for (int i = 0 ; i < 3 ; i ++) {
8
+ Ball ball = lottery .getRandomBall ();
9
+ System .out .println (ball );
10
+ }
14
11
}
15
12
}
Original file line number Diff line number Diff line change 1
1
package core .basesyntax ;
2
2
3
3
public class Ball {
4
- private Color color ;
4
+ private String color ;
5
5
private int number ;
6
6
7
- public Ball (Color color , int number ) {
7
+ public Ball (String color , int number ) {
8
8
this .color = color ;
9
9
this .number = number ;
10
10
}
Original file line number Diff line number Diff line change 5
5
public class ColorSupplier {
6
6
private Random random = new Random ();
7
7
8
- public Color getRandomColor () {
8
+ public String getRandomColor () {
9
9
int index = random .nextInt (Color .values ().length );
10
- return Color .values ()[index ];
10
+ return Color .values ()[index ]. name () ;
11
11
}
12
12
}
Original file line number Diff line number Diff line change 3
3
import java .util .Random ;
4
4
5
5
public class Lottery {
6
+ private static final int MAX_NUMBER =100 ;
6
7
private Random random = new Random ();
7
8
private ColorSupplier colorSupplier = new ColorSupplier ();
8
9
9
10
public Ball getRandomBall () {
10
- Color color = colorSupplier .getRandomColor ();
11
- int number = random .nextInt (100 ) + 1 ;
11
+ String color = colorSupplier .getRandomColor ();
12
+ int number = random .nextInt (MAX_NUMBER ) + 1 ;
12
13
return new Ball (color , number );
13
14
}
14
-
15
15
}
You can’t perform that action at this time.
0 commit comments