File tree Expand file tree Collapse file tree 5 files changed +17
-18
lines changed 
src/main/java/core/basesyntax Expand file tree Collapse file tree 5 files changed +17
-18
lines changed Original file line number Diff line number Diff line change 11package  core .basesyntax ;
22
33public  class  Application  {
4+     private  static  final  int  NUMBER_OF_BALLS  = 3 ;
5+ 
46    public  static  void  main (String [] args ) {
5-         // create three balls using class Lottery and print information about them in console 
67        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 ());
8+         for  (int  i  = 0 ; i  < NUMBER_OF_BALLS ; i ++) {
9+             Ball  ball  = lottery .getRandomBall ();
10+             System .out .println (ball .toString ());
11+         }
1312    }
1413}
Original file line number Diff line number Diff line change 22
33public  class  Ball  {
44
5-     private  String  colour ;
5+     private  String  color ;
66
77    private  int  number ;
88
9-     public  Ball (String  colour , int  number ) {
10-         this .colour  = colour ;
9+     public  Ball (String  color , int  number ) {
10+         this .color  = color ;
1111        this .number  = number ;
1212    }
1313
1414    @ Override 
1515    public  String  toString () {
16-         return  "Ball colour is "  + colour 
16+         return  "Ball colour is "  + color 
1717            + " number is "  + number ;
1818    }
1919}
Original file line number Diff line number Diff line change 33import  java .util .Random ;
44
55public  class  ColorSupplier  {
6+     private  final  Random  random  = new  Random ();
7+ 
68    public  String  getRandomColor () {
7-         int  index  = new  Random ().nextInt (Colours .values ().length );
8-         Colours  colour  = Colours .values ()[index ];
9-         return  colour .toString ();
9+         return  Colors .values ()[random .nextInt (Colors .values ().length )].name ();
1010    }
1111}
Original file line number Diff line number Diff line change 11package  core .basesyntax ;
22
3- public  enum  Colours  {
3+ public  enum  Colors  {
44    PINK ,
55    PURPLE ,
66    BLUE ,
Original file line number Diff line number Diff line change 33import  java .util .Random ;
44
55public  class  Lottery  {
6+     private  static  final  int  MAX_NUMBER  = 101 ;
67    private  final  ColorSupplier  colorSupplier  = new  ColorSupplier ();
8+     private  final  Random  random  = new  Random ();
79
810    public  Ball  getRandomBall () {
9-         String  randomColour  = colorSupplier .getRandomColor ();
10-         int  randomNumber  = new  Random ().nextInt (100 );
11-         return  new  Ball (randomColour , randomNumber );
11+         return  new  Ball (colorSupplier .getRandomColor (), random .nextInt (MAX_NUMBER ));
1212    }
1313}
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments