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
1 parent
98bb7f0
commit 3e32932
Showing
6 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 org.example; | ||
|
||
public class Ball { | ||
private Color color; | ||
private int number; | ||
|
||
public Ball(Color 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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.example; | ||
|
||
public enum Color { | ||
RED, BLUE, WHITE, GREEN, ORANGE, BLACK, 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,14 @@ | ||
package core.basesyntax; | ||
package org.example; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
|
||
private final Color[] colors = Color.values(); | ||
private final Random random = new Random(); | ||
|
||
public Color getRandomColor() { | ||
|
||
return colors[random.nextInt(colors.length)]; | ||
} | ||
} |
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 org.example; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
|
||
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
||
private final Random random = new Random(); | ||
|
||
public Ball getRandomBall() { | ||
|
||
return new Ball(colorSupplier.getRandomColor(), random.nextInt(100)); | ||
} | ||
} |
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,21 @@ | ||
package org.example; | ||
|
||
public class Main { | ||
public static void main(String[] args) { | ||
|
||
Lottery lottery = new Lottery(); | ||
|
||
for (int i = 1; i < 4; i++) | ||
{ | ||
Ball ball = lottery.getRandomBall(); | ||
if (i == 1) { | ||
System.out.print(i + "st "); | ||
} else if (i == 2) { | ||
System.out.print(i + "nd "); | ||
} else if (i == 3) { | ||
System.out.print(i + "rd "); | ||
} | ||
System.out.println(ball); | ||
} | ||
} | ||
} |