Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
xMax committed Dec 31, 2024
1 parent 98bb7f0 commit cf5f58c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery[] balls = { new Lottery(), new Lottery(), new Lottery() };
for (Lottery ball : balls) {
System.out.println(ball.getRandomBall());
}
}
}
27 changes: 27 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package core.basesyntax;

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

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

public String getColor() {
return this.color.toString();
}

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

public int getNumber() {
return this.number;
}

@Override
public String toString() {
return super.toString();
}
}
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 java.util.Random;

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

public enum Colors {
Red,
Blue,
Green,
Yellow,
Orange,
Black
}
14 changes: 14 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package core.basesyntax;

import java.util.Random;

public class Lottery {
public String getRandomBall() {
Ball ball = new Ball();
ColorSupplier colorSupplier = new ColorSupplier();
colorSupplier.getRandomColor(ball);
int randomValue = new Random().nextInt(100);
ball.setNumber(randomValue);
return ball.getColor() + " " + ball.getNumber();
}
}

0 comments on commit cf5f58c

Please sign in to comment.