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 ENUM, Ball, Color, Lottery classes. Implemented methods in th…
…em according to the given task. Tested the program using the Main class.
- Loading branch information
Showing
5 changed files
with
53 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,16 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
private String color; | ||
private int number; | ||
|
||
public Ball(String color, int number) { | ||
this.color = color; | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Return Ball with number:" + number + " and " + color + " colore"; | ||
} | ||
} |
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,10 @@ | ||
package core.basesyntax; | ||
|
||
public enum Color { | ||
BLACK, | ||
WHITE, | ||
GREEN, | ||
YELLOU, | ||
RED, | ||
BLUE | ||
} |
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,12 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private Random random = new Random(); | ||
|
||
public String getRandomColor() { | ||
return null; | ||
int index = random.nextInt(Color.values().length); | ||
return Color.values()[index].name(); | ||
} | ||
} |
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,15 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
private static final int MAXIMUM_NUMBER = 100; | ||
private Random random = new Random(); | ||
private ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
||
public Ball getRandomBall() { | ||
String color = colorSupplier.getRandomColor(); | ||
int ballNumber = random.nextInt(MAXIMUM_NUMBER) + 1; | ||
return new Ball(color, ballNumber); | ||
} | ||
} |