-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Solution implementation #2008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Solution implementation #2008
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public class Application { | ||
| public static final int ballAmount = 3; | ||
|
|
||
| public static void main(String[] args) { | ||
| // create three balls using class Lottery and print information about them in console | ||
|
|
||
| for (int i = 0; i < ballAmount; i++) { | ||
| System.out.println(new Lottery().getRandomBall()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 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 "Ball{" | ||
| + "color='" | ||
| + color | ||
| + '\'' | ||
| + ", number=" | ||
| + number | ||
| + '}'; | ||
| } | ||
| } |
| 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; | ||||||
| public static String getRandomColor() { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| ColorsEnum [] colors = ColorsEnum.values(); | ||||||
| int index = new Random().nextInt(colors.length); | ||||||
| return colors[index].toString(); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,9 @@ | ||||||
| package core.basesyntax; | ||||||
|
|
||||||
| public enum ColorsEnum { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| RED, | ||||||
| BLUE, | ||||||
| GREEN, | ||||||
| YELLOW, | ||||||
| VIOLET, | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Lottery { | ||
| public static final int NumberBound = 100; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment about constant |
||
|
|
||
| public Ball getRandomBall() { | ||
| String randomColor = ColorSupplier.getRandomColor(); | ||
| int randomNumber = new Random().nextInt(NumberBound); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return new Ball(randomColor, randomNumber); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget how to name constants according to style guide (the same with naming of enum values)