Skip to content

Commit

Permalink
created a lottery class with the getRandomBall method, which returns …
Browse files Browse the repository at this point in the history
…ball.
  • Loading branch information
vooloshkaaa committed Jan 10, 2025
1 parent 5631fad commit 007329c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
7 changes: 7 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,12 @@
public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Ball firstBall = new Lottery().getRandomBall();
Ball secondBall = new Lottery().getRandomBall();
Ball thirdBall = new Lottery().getRandomBall();

System.out.println(firstBall.toString());
System.out.println(secondBall.toString());
System.out.println(thirdBall.toString());
}
}
20 changes: 17 additions & 3 deletions src/main/java/core/basesyntax/Ball.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
package core.basesyntax;

public class Ball {
private String color;
private int number;
final String color;
final int number;

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

public String getColor() {
return color;
}

public int getNumber() {
return number;
}

@Override
public String toString() {
return super.toString();
return "Information about ball:\n color: " + getColor().toLowerCase() + " number: " + getNumber();
}

}
2 changes: 1 addition & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.util.Random;

public class ColorSupplier {
public String getRandomColor() {
public static String getRandomColor() {
int index = new Random().nextInt(Color.values().length);
Color color = Color.values()[index];
return color.toString();
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/core/basesyntax/Lottery.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package core.basesyntax;

import java.util.Random;

public class Lottery {
public Ball getRandomBall() {
String newBallColor = ColorSupplier.getRandomColor();
int newBallNumber = new Random().nextInt(100);
return new Ball(newBallColor, newBallNumber);
}
}

0 comments on commit 007329c

Please sign in to comment.