-
Notifications
You must be signed in to change notification settings - Fork 1.6k
2 #2013
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?
2 #2013
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 |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public class Ball { | ||
| private String color; | ||
| private int number; | ||
|
|
||
| public Ball(String color, int number) { | ||
| this.color = color; | ||
| this.number = number; | ||
| } | ||
|
|
||
| public String getColor() { | ||
| return color; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Color is " + color + " and number is " + number; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,19 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
|
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. This file has a redundant empty line after the |
||
| public class ColorSupplier { | ||
| public enum Colors { | ||
| RED, | ||
| YELLOW, | ||
| WHITE, | ||
| BLACK, | ||
| BLUE | ||
| } | ||
|
|
||
|
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. There is a redundant empty line after the enum closing |
||
| private final Random random = new Random(); | ||
|
|
||
|
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. There is a redundant empty line after the |
||
| public String getRandomColor() { | ||
| return null; | ||
| return Colors.values()[random.nextInt(Colors.values().length)].name(); | ||
| } | ||
| } | ||
| 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 MAX_NUMBER = 100; | ||
| private final Random random = new Random(); | ||
| private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
|
||
| public Ball getRandomBall() { | ||
| int number = random.nextInt(MAX_NUMBER) + 1; // 1..100 | ||
| String color = colorSupplier.getRandomColor(); | ||
| return new Ball(color, number); | ||
|
Comment on lines
+11
to
+13
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. This creates temporary local variables ( |
||
| } | ||
| } | ||
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.
This violates checklist item #9: "All magic numbers in your code should be constants." Declare a constant like
private static final int BALL_COUNT = 3;in theApplicationclass and usei < BALL_COUNTin the loop instead of the literal3.