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
xMax
committed
Dec 31, 2024
1 parent
98bb7f0
commit cf5f58c
Showing
5 changed files
with
62 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,27 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
private Colors color; | ||
private int number; | ||
|
||
public void setColor(Colors color) { | ||
this.color = color; | ||
} | ||
|
||
public String getColor() { | ||
return this.color.toString(); | ||
} | ||
|
||
public void setNumber(int number) { | ||
this.number = number; | ||
} | ||
|
||
public int getNumber() { | ||
return this.number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return super.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 |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
public String getRandomColor(Ball ball) { | ||
Random random = new Random(); | ||
int index = random.nextInt(Colors.values().length); | ||
ball.setColor(Colors.values()[index]); | ||
return ball.getColor(); | ||
} | ||
} |
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 Colors { | ||
Red, | ||
Blue, | ||
Green, | ||
Yellow, | ||
Orange, | ||
Black | ||
} |
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 { | ||
public String getRandomBall() { | ||
Ball ball = new Ball(); | ||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
colorSupplier.getRandomColor(ball); | ||
int randomValue = new Random().nextInt(100); | ||
ball.setNumber(randomValue); | ||
return ball.getColor() + " " + ball.getNumber(); | ||
} | ||
} |