File tree Expand file tree Collapse file tree 3 files changed +13
-10
lines changed
src/main/java/core/basesyntax Expand file tree Collapse file tree 3 files changed +13
-10
lines changed Original file line number Diff line number Diff line change 33public class Application {
44 public static void main (String [] args ) {
55 Lottery lottery = new Lottery ();
6- lottery .getRandomBall ();
7- lottery .getRandomBall ();
8- lottery .getRandomBall ();
6+ Ball ball = new Ball ();
7+ int ballsQuantity = 3 ;
8+ for (int i = 0 ; i < ballsQuantity ; i ++) {
9+ lottery .getRandomBall (ball );
10+ }
911 }
1012}
Original file line number Diff line number Diff line change 44
55public class ColorSupplier {
66
7- public String getRandomColor () {
7+ public static String getRandomColor () {
88 int index = new Random ().nextInt (Colors .values ().length );
99 String randomColor = String .valueOf (Colors .values ()[index ]);
1010 return randomColor ;
Original file line number Diff line number Diff line change 22
33import java .util .Random ;
44
5- public class Lottery extends Ball {
5+ public class Lottery {
66
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 ());
7+ public Ball getRandomBall (Ball ball ) {
8+ int maxNumber = 100 ;
9+ ball .setNumber (new Random ().nextInt (maxNumber ));
10+ ball .setColor (ColorSupplier .getRandomColor ());
11+ System .out .println ("The ball with number " + ball .getNumber () + " is " + ball .getColor ());
12+ return ball ;
1213 }
1314}
You can’t perform that action at this time.
0 commit comments