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 2 commits
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.

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

import mate.academy.supplier.Lottery;

public class Application {
private static final int NUMBER_OF_BALLS = 3;

public static void main(String[] args) {
Lottery lottery = new Lottery();
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
}
12 changes: 12 additions & 0 deletions src/main/java/mate/academy/supplier/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package mate.academy.supplier;

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

public class ColorSupplier {
private final Random random = new Random();

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

return Color.values()[random.nextInt(Color.values().length)];
}
}
17 changes: 17 additions & 0 deletions src/main/java/mate/academy/supplier/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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;
private final ColorSupplier colorSupplier = new ColorSupplier();
private final Random random = new Random();

public Ball getRandomBall() {
Color color = colorSupplier.getRandomColor();
int number = random.nextInt(MAX_NUMBER);
return new Ball(color, number);
}
}
Loading