generated from mate-academy/jv-homework-template
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created a lottery about balls with random number and color
- Loading branch information
1 parent
98bb7f0
commit ca859f3
Showing
5 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
private final String color; | ||
private final int number; | ||
|
||
public Ball(String color, int number) { | ||
this.color = color; | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Ball{" + | ||
"color='" + color + '\'' + | ||
", number=" + number + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
int index = new Random().nextInt(Colors.values().length); | ||
Colors color = Colors.values()[index]; | ||
return color.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package core.basesyntax; | ||
|
||
public enum Colors { | ||
YELLOW, | ||
BLUE, | ||
PINK, | ||
PURPLE, | ||
GREEN, | ||
RED, | ||
WHITE, | ||
BROWN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
private final Random random = new Random(); | ||
|
||
public Ball getRandomBall() { | ||
String randomColor = colorSupplier.getRandomColor(); | ||
int randomNumber = random.nextInt(101); | ||
return new Ball(randomColor, randomNumber); | ||
} | ||
} |