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.
- Loading branch information
Showing
5 changed files
with
83 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,38 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
private String color; | ||
private Long number; | ||
|
||
public Ball(String color, Long number) { | ||
this.color = color; | ||
this.number = number; | ||
} | ||
|
||
public Ball() { | ||
} | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(String color) { | ||
this.color = color; | ||
} | ||
|
||
public Long getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(Long number) { | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package core.basesyntax; | ||
|
||
public enum Color { | ||
RED, | ||
BLUE, | ||
GREEN, | ||
YELLOW, | ||
ORANGE, | ||
PURPLE | ||
} |
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,15 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private final Random random = new Random(); | ||
|
||
public String getRandomColor() { | ||
return null; | ||
return Color.values()[getRandom().nextInt(Color.values().length)].toString(); | ||
} | ||
|
||
public Random getRandom() { | ||
return random; | ||
} | ||
} |
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,22 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
private final Random random = new Random(); | ||
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
||
public String getRandomBall() { | ||
String color = getColorSupplier().getRandomColor(); | ||
Long number = getRandom().nextLong(100); | ||
return new Ball(color, number).toString(); | ||
} | ||
|
||
public ColorSupplier getColorSupplier() { | ||
return colorSupplier; | ||
} | ||
|
||
public Random getRandom() { | ||
return random; | ||
} | ||
} |