Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

VitaliyJvM
Copy link

No description provided.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove comment

Comment on lines 12 to 15
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());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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());

Comment on lines 4 to 10
private Color color;
private int number;

public Ball(Color color, int number) {
this.color = color;
this.number = number;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;
}

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

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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ "color=" + color.name()
+ "color=" + color

import mate.academy.model.Color;

public class ColorSupplier {
public Color getRandomColor() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public Color getRandomColor() {
public String getRandomColor() {


public class ColorSupplier {
public Color getRandomColor() {
int index = new Random().nextInt(Color.values().length);

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();

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();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Color color = new ColorSupplier().getRandomColor();
String color = colorSupplier.getRandomColor();

Comment on lines 4 to 10
private Color color;
private int number;

public Ball(Color color, int number) {
this.color = color;
this.number = number;
}

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants