-
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
Create a simple lottery #1276
base: master
Are you sure you want to change the base?
Create a simple lottery #1276
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.
Looks like not all files of project were commited or pushed
public String getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(String color) { | ||
this.color = color; | ||
} | ||
|
||
public Integer getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(Integer number) { | ||
this.number = 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.
Better use constructor for init Ball object
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
int inedex = new Random().nextInt(Colors.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.
Red, | ||
Blue, | ||
Yellow, | ||
White, | ||
Green, | ||
Orange, | ||
Violet |
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.
Enum style
Random random = new Random(); | ||
ball.setNumber(random.nextInt(100)); | ||
ColorSupplier supplier = new ColorSupplier(); |
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 random = new Random(); | ||
ball.setNumber(random.nextInt(100)); | ||
ColorSupplier supplier = new ColorSupplier(); | ||
ball.setColor(supplier.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.
Init ball by constructor
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
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.
Create Random in field of class, cause every invoke of method create new object!
Random random = new Random(); | ||
ColorSupplier supplier = new ColorSupplier(); |
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.
Same situation, save it in field
public Ball getRandomBall() { | ||
Random random = new Random(); | ||
ColorSupplier supplier = new ColorSupplier(); | ||
int randomNumber = random.nextInt(100); |
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.
Magic number 100, what about constant?
int inedex = random.nextInt(Colors.values().length); | ||
return Colors.values()[inedex].toString(); |
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.
index misspelled, don't use toString - revisit checklist, this issue is mentioned there
@@ -0,0 +1,11 @@ | |||
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 { |
enum should be in singular
public class Lottery { | ||
private Random random = new Random(); | ||
private ColorSupplier supplier = new ColorSupplier(); | ||
private int maxNumber = 100; |
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.
make it constant - static final + MAX_NUMBER, and change to 101, because the value passed to randomizer is excluded itself
public Ball getRandomBall() { | ||
int randomNumber = random.nextInt(maxNumber); | ||
String randomColor = supplier.getRandomColor(); | ||
return new Ball(randomColor,randomNumber); |
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.
we need space after comma, format your files in IDEA before committing (Ctrl Alt L)
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
No description provided.