File tree Expand file tree Collapse file tree 5 files changed +55
-1
lines changed
src/main/java/core/basesyntax Expand file tree Collapse file tree 5 files changed +55
-1
lines changed Original file line number Diff line number Diff line change 33public class Application {
44 public static void main (String [] args ) {
55 // create three balls using class Lottery and print information about them in console
6+ 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 ());
613 }
714}
Original file line number Diff line number Diff line change 1+ package core .basesyntax ;
2+
3+ public class Ball {
4+
5+ private String colour ;
6+
7+ private int number ;
8+
9+ public Ball (String colour , int number ) {
10+ this .colour = colour ;
11+ this .number = number ;
12+ }
13+
14+ @ Override
15+ public String toString () {
16+ return "Ball colour is " + colour
17+ + " number is " + number ;
18+ }
19+ }
Original file line number Diff line number Diff line change 11package core .basesyntax ;
22
3+ import java .util .Random ;
4+
35public class ColorSupplier {
46 public String getRandomColor () {
5- return null ;
7+ int index = new Random ().nextInt (Colours .values ().length );
8+ Colours colour = Colours .values ()[index ];
9+ return colour .toString ();
610 }
711}
Original file line number Diff line number Diff line change 1+ package core .basesyntax ;
2+
3+ public enum Colours {
4+ PINK ,
5+ PURPLE ,
6+ BLUE ,
7+ RED ,
8+ GREEN ,
9+ BLACK ,
10+ WHITE
11+ }
Original file line number Diff line number Diff line change 1+ package core .basesyntax ;
2+
3+ import java .util .Random ;
4+
5+ public class Lottery {
6+ private final ColorSupplier colorSupplier = new ColorSupplier ();
7+
8+ public Ball getRandomBall () {
9+ String randomColour = colorSupplier .getRandomColor ();
10+ int randomNumber = new Random ().nextInt (100 );
11+ return new Ball (randomColour , randomNumber );
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments