Skip to content

Commit

Permalink
solution lottery
Browse files Browse the repository at this point in the history
  • Loading branch information
Serhiircv committed Nov 27, 2024
1 parent 98bb7f0 commit bf474db
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console

Lottery ball1 = new Lottery();
Lottery ball2 = new Lottery();
Lottery ball3 = new Lottery();

System.out.println(ball1.getRandomBall());
System.out.println(ball2.getRandomBall());
System.out.println(ball3.getRandomBall());
}
}
37 changes: 37 additions & 0 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package core.basesyntax;

public class Ball {

private String color;
private int number;

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

public String getColor() {
return color;
}

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

public int getNumber() {
return number;
}

@Override
public String toString() {

return "Ball: " + "color = " + color + ", " + "number = " + number;
}
}








7 changes: 6 additions & 1 deletion 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 {
String randomColor = getRandomColor();

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

public enum Colors {
GREEN,
RED,
YELLOW,
ORANGE,
BLACK,
WHITE,
BLUE,
GRAY,
VIOLET,
BROWN
}
15 changes: 15 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package core.basesyntax;

import java.util.Random;

public class Lottery extends ColorSupplier {
Random random = new Random();
int randomInt = random.nextInt(100);

public Ball getRandomBall() {
Ball randomBall = new Ball();
randomBall.setColor(randomColor);
randomBall.setNumber(randomInt);
return randomBall;
}
}

0 comments on commit bf474db

Please sign in to comment.