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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/main/java/core/basesyntax/Application.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/core/basesyntax/ColorSupplier.java

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/mate/academy/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mate.academy;

import mate.academy.model.Ball;
import mate.academy.supplier.Lottery;

public class Application {
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

Lottery lottery = new Lottery();
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());

}
}
}
35 changes: 35 additions & 0 deletions src/main/java/mate/academy/model/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package mate.academy.model;

public class Ball {
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)


public Color getColor() {
return color;
}

public void setColor(Color color) {
this.color = color;
}

public int getNumber() {
return number;
}

public void setNumber(int number) {
this.number = number;
}

@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

+ ", number=" + number
+ '}';
}
}
11 changes: 11 additions & 0 deletions src/main/java/mate/academy/model/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mate.academy.model;

public enum Color {
RED,
GREEN,
YELLOW,
BLUE,
WHITE,
BLACK,
ORANGE
}
11 changes: 11 additions & 0 deletions src/main/java/mate/academy/supplier/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package mate.academy.supplier;

import java.util.Random;
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() {

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

return Color.values()[index];
}
}
15 changes: 15 additions & 0 deletions src/main/java/mate/academy/supplier/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package mate.academy.supplier;

import java.util.Random;
import mate.academy.model.Ball;
import mate.academy.model.Color;

public class Lottery {
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

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

int number = new Random().nextInt(MAX_NUMBER);
return new Ball(color, number);
}
}
Loading