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 all 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 String color;
private int number;

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

public String getColor() {
return color;
}

public void setColor(String 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
+ ", 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 String getRandomColor() {
return Color.values()[random.nextInt(Color.values().length)].name();
}
}
16 changes: 16 additions & 0 deletions src/main/java/mate/academy/supplier/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package mate.academy.supplier;

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

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() {
String color = colorSupplier.getRandomColor();
int number = random.nextInt(MAX_NUMBER);
return new Ball(color, number);
}
}
Loading