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

Task jv lottery #1738

Open
wants to merge 5 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: 6 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

import core.basesyntax.classes.Lottery;

public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery lottery = new Lottery();
for (int order = 0; order < 3; order++) {
DenDy1227 marked this conversation as resolved.
Show resolved Hide resolved
System.out.println(lottery.getRandomBall().getBallInfo());
}
}
}
9 changes: 7 additions & 2 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package core.basesyntax;

import core.basesyntax.classes.Color;
import java.util.Random;

public class ColorSupplier {
public String getRandomColor() {
return null;
public Color getRandomColor() {
Color[] colors = Color.values();
Random random = new Random();
return colors[random.nextInt(colors.length)];
}
}
23 changes: 23 additions & 0 deletions src/main/java/core/basesyntax/classes/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package core.basesyntax.classes;

public class Ball {
private Color color;
private int number;

Ball(Color color, int number) {
DenDy1227 marked this conversation as resolved.
Show resolved Hide resolved
this.color = color;
this.number = number;
}

public Color getColor() {
return color;
}

public int getNumber() {
return number;
}

public String getBallInfo() {
return String.format("Ball of %s color, with number %d", this.color, this.number);
}
}
10 changes: 10 additions & 0 deletions src/main/java/core/basesyntax/classes/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package core.basesyntax.classes;

public enum Color {
RED, GREEN, BLUE, YELLOW, VIOLET, BLACK;

@Override
public String toString() {
return name();
}
}
13 changes: 13 additions & 0 deletions src/main/java/core/basesyntax/classes/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package core.basesyntax.classes;

import core.basesyntax.ColorSupplier;
import java.util.Random;

public class Lottery {

public Ball getRandomBall() {
Random random = new Random();
ColorSupplier color = new ColorSupplier();
return new Ball(color.getRandomColor(), random.nextInt(100));
}
}
Loading