File tree Expand file tree Collapse file tree 5 files changed +64
-2
lines changed
src/main/java/core/basesyntax Expand file tree Collapse file tree 5 files changed +64
-2
lines changed Original file line number Diff line number Diff line change 22
33public class Application {
44 public static void main (String [] args ) {
5- // create three balls using class Lottery and print information about them in console
5+ Lottery lottery = new Lottery ();
6+ lottery .getRandomBall ();
7+ lottery .getRandomBall ();
8+ lottery .getRandomBall ();
69 }
710}
Original file line number Diff line number Diff line change 1+ package core .basesyntax ;
2+
3+ public class Ball {
4+ private String color ;
5+ private int number ;
6+
7+ public String getColor () {
8+ return color ;
9+ }
10+
11+ public void setColor (String color ) {
12+ this .color = color ;
13+ }
14+
15+ public int getNumber () {
16+ return number ;
17+ }
18+
19+ public void setNumber (int number ) {
20+ this .number = number ;
21+ }
22+
23+ @ Override
24+ public String toString () {
25+ return "Ball{"
26+ + "color='" + color + '\''
27+ + ", number=" + number
28+ + '}' ;
29+ }
30+ }
Original file line number Diff line number Diff line change 11package core .basesyntax ;
22
3+ import java .util .Random ;
4+
35public class ColorSupplier {
6+
47 public String getRandomColor () {
5- return null ;
8+ int index = new Random ().nextInt (Colors .values ().length );
9+ String randomColor = String .valueOf (Colors .values ()[index ]);
10+ return randomColor ;
611 }
712}
Original file line number Diff line number Diff line change 1+ package core .basesyntax ;
2+
3+ public enum Colors {
4+ RED ,
5+ ORANGE ,
6+ YELLOW ,
7+ GREEN ,
8+ BLUE ,
9+ INDIGO ,
10+ VIOLET
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 extends Ball {
6+
7+ public void getRandomBall () {
8+ ColorSupplier colorSupplier = new ColorSupplier ();
9+ setNumber (new Random ().nextInt (100 ));
10+ setColor (colorSupplier .getRandomColor ());
11+ System .out .println ("The ball with number " + getNumber () + " is " + getColor ());
12+ }
13+ }
You can’t perform that action at this time.
0 commit comments