-
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
Implement Lottery #1703
base: master
Are you sure you want to change the base?
Implement Lottery #1703
Conversation
# Conflicts: # src/main/java/core/basesyntax/Lottery.java
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.
Let's check the common mistakes list and fix your solution by list ;)
private final Colors color; | ||
private final int number; |
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 Colors color; | |
private final int number; | |
private Colors color; | |
private int number; |
@@ -0,0 +1,14 @@ | |||
package core.basesyntax; | |||
|
|||
public enum Colors { |
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 enum Colors { | |
public enum 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.
Let’s check the common mistakes list again
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
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.
public static Color getRandomColor() { | |
public Color getRandomColor() { |
Don't use static methods in your solution (from common mistakes)
public String getRandomColor() { | ||
return null; | ||
public static Color getRandomColor() { | ||
return Color.values()[new Random().nextInt(Color.values().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.
Think about which variables should be local in the method and which should be class-level (following common mistakes)
public static Ball getRandomBall() { | ||
return new Ball(ColorSupplier.getRandomColor(), new Random().nextInt(101)); | ||
} |
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.
the same Also, All magic numbers in your code should be constants. (from common mistakes)
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.
Good job! But fix my comments ;)
|
||
public void main(String[] args) { | ||
for (int i = 0; i < BALL_COUNT; i++) { | ||
System.out.println(new Lottery().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.
in this realization, you create 3 new instances one instant is enough
public void main(String[] args) { | ||
for (int i = 0; i < BALL_COUNT; i++) { | ||
System.out.println(new Lottery().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.
public void main(String[] args) { | |
for (int i = 0; i < BALL_COUNT; i++) { | |
System.out.println(new Lottery().getRandomBall()); | |
public void main(String[] args) { | |
Lottery lottery = new Lottery(); | |
for (int i = 0; i < BALL_COUNT; i++) { | |
System.out.println(lottery.getRandomBall()); |
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
private 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.
private Random random = new Random(); | |
private final Random random = new Random(); |
private Random random = new Random(); | ||
|
||
public Ball getRandomBall() { | ||
return new Ball(new ColorSupplier().getRandomColor(), random.nextInt(BALL_NUMBER)); |
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 Random random = new Random(); | |
public Ball getRandomBall() { | |
return new Ball(new ColorSupplier().getRandomColor(), random.nextInt(BALL_NUMBER)); | |
private final Random random = new Random(); | |
private final ColorSupplier supplier = new ColorSupplier() | |
public Ball getRandomBall() { | |
return new Ball(supplier.getRandomColor(), random.nextInt(BALL_NUMBER)); |
No description provided.