-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Main #2023
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?
Main #2023
Changes from all commits
b5b93fe
442b7d2
3243152
b65ac46
eda3252
cb514e6
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,54 @@ | ||
| import java.util.Random; | ||
|
|
||
| public class Lottery { | ||
|
|
||
| public enum Color { | ||
| GREEN, BLUE, PURPLE, WHITE, BLACK, YELLOW, ORANGE | ||
| } | ||
|
|
||
| public static class ColorSupplier { | ||
| private final Random random = new Random(); | ||
|
|
||
| public String getRandomColor() { | ||
| Color[] colors = Color.values(); | ||
| return colors[random.nextInt(colors.length)].name(); | ||
| } | ||
| } | ||
|
|
||
| public static class Ball { | ||
| private final String color; | ||
| private final int number; | ||
|
|
||
| public Ball(String color, int number) { | ||
| this.color = color; | ||
| this.number = number; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Ball: " + color + ", number: " + number; | ||
| } | ||
| } | ||
|
|
||
| public static class Lottery { | ||
|
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 nested class has the same name as its outer class ( |
||
| private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
| private final Random random = new Random(); | ||
| private static final int MAX_NUMBER = 100; | ||
|
|
||
| public Ball getRandomBall() { | ||
| return new Ball(colorSupplier.getRandomColor(), random.nextInt(MAX_NUMBER + 1)); | ||
| } | ||
| } | ||
|
Comment on lines
+5
to
+41
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. As mentioned in the previous review, the |
||
|
|
||
| private static final int DRAW_COUNT = 3; | ||
|
|
||
| public static void main(String[] args) { | ||
| Lottery lottery = new Lottery(); | ||
|
|
||
| System.out.println("Drawing " + DRAW_COUNT + " balls:"); | ||
|
|
||
| for (int i = 1; i <= DRAW_COUNT; i++) { | ||
| System.out.println("Draw number:" + i + lottery.getRandomBall()); | ||
| } | ||
| } | ||
| } | ||
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 #3: 'Don't use static methods in your solution'. While the methods inside are not static (which is correct), the class itself should not be
static. The classesColorSupplier,Ball, andLotteryshould be regular top-level classes, each in its own file.