-
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
the ball lottery was created #1689
base: master
Are you sure you want to change the base?
Conversation
private static final int NUMBER_OF_BALLS = 3; | ||
|
||
public static void main(String[] args) { | ||
// create three balls using class Lottery and print information about them in console |
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.
remove comment
Ball[] balls = new Ball[NUMBER_OF_BALLS]; | ||
for (int i = 0; i < balls.length; i++) { | ||
balls[i] = lottery.getRandomBall(); | ||
System.out.println(balls[i].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.
Ball[] balls = new Ball[NUMBER_OF_BALLS]; | |
for (int i = 0; i < balls.length; i++) { | |
balls[i] = lottery.getRandomBall(); | |
System.out.println(balls[i].toString()); | |
for (int i = 0; i < NUMBER_OF_BALLS; i++) { | |
System.out.println(lottery.getRandomBall()); |
private Color color; | ||
private int number; | ||
|
||
public Ball(Color color, int number) { | ||
this.color = color; | ||
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.
private Color color; | |
private int number; | |
public Ball(Color color, int number) { | |
this.color = color; | |
this.number = number; | |
} | |
private String color; | |
private int number; | |
public Ball(String color, int number) { | |
this.color = color; | |
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.
It's better to provide already prepared String where is needed
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 fix the comment)
@Override | ||
public String toString() { | ||
return "Ball{" | ||
+ "color=" + color.name() |
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.
+ "color=" + color.name() | |
+ "color=" + color |
import mate.academy.model.Color; | ||
|
||
public class ColorSupplier { | ||
public 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 Color getRandomColor() { | |
public String getRandomColor() { |
|
||
public class ColorSupplier { | ||
public Color getRandomColor() { | ||
int index = 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.
Random should be class-level variable
private static final int MAX_NUMBER = 100; | ||
|
||
public Ball getRandomBall() { | ||
Color color = new ColorSupplier().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.
ColorSupplier and Random shoud be class-level variables
private static final int MAX_NUMBER = 100; | ||
|
||
public Ball getRandomBall() { | ||
Color color = new ColorSupplier().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.
Color color = new ColorSupplier().getRandomColor(); | |
String color = colorSupplier.getRandomColor(); |
private Color color; | ||
private int number; | ||
|
||
public Ball(Color color, int number) { | ||
this.color = color; | ||
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.
Let's fix the comment)
No description provided.