-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LotterySolution #1293
base: master
Are you sure you want to change the base?
LotterySolution #1293
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
94def62
to
49fae00
Compare
763e8a3
to
49fae00
Compare
Please, check my new commit "LotteryRemodeled" |
//Creating type of color | ||
public static Color getRandomColor() { | ||
|
||
Random random = new Random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random should be instantiated once and reused multiple times,
nor creating each time the getRandomColor method is invoked
return null; | ||
|
||
//Creating type of color | ||
public static Color getRandomColor() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont use static
public static Color getRandomColor() { | |
public Color getRandomColor() { |
public class Lottery { | ||
public static Ball getRandomBall() { | ||
String colorRandom = ColorSupplier.getRandomColor().toString(); //1 | ||
Random random = new Random(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
random should be instantiated once
public static Ball getRandomBall() { | ||
String colorRandom = ColorSupplier.getRandomColor().toString(); //1 | ||
Random random = new Random(); | ||
int numberRandom = random.nextInt(100) + 1; //2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100 is a magic number, avoid using magic numbers
should be constant with proper name
int numberRandom = random.nextInt(100) + 1; //2 | |
int numberRandom = random.nextInt(100) + 1; //2 |
import java.util.Random; | ||
|
||
public class Lottery { | ||
public static Ball getRandomBall() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont use static
public static Ball getRandomBall() { | |
public Ball getRandomBall() { |
Please, check my fixed commit "Fixed task balls".. |
6a3b9fe
to
3e32932
Compare
c365b8e
to
3e32932
Compare
public class Ball { | ||
|
||
private Color color; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ '}'; | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+ '}'; | |
} | |
+ '}'; | |
} |
public Ball(Color color, int number) { | ||
|
||
this.color = color; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
private final Color[] colors = Color.values(); | ||
private final Random random = new Random(); | ||
|
||
public Color getRandomColor() { | ||
|
||
return colors[random.nextInt(colors.length)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
7792ffa
to
3e32932
Compare
d1b3ea3
to
3e32932
Compare
No description provided.