-
Notifications
You must be signed in to change notification settings - Fork 1.6k
OOP Lottery Practice #2020
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?
OOP Lottery Practice #2020
Changes from all commits
3b22b62
8dac66d
84e6f60
7127d8e
6e3d973
4e26f1e
30d6973
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 void main(String[] args) { | ||
| // create three balls using class Lottery and print information about them in console | ||
| final int NM = 3; | ||
| Lottery lottery = new Lottery(); | ||
| for (int i = 0; i < NM; i++) { | ||
| System.out.println(lottery.getRandomBall()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package core.basesyntax; | ||
|
|
||
|
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. The checklist also asks to avoid redundant empty lines around class/method signatures (see: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature."). Remove the blank line between the |
||
| public class Ball { | ||
| private final String color; | ||
| private final int number; | ||
|
|
||
|
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 violates the checklist requirement: "Remove the extra blank lines after the class declaration, before the constructor, and between the constructor and |
||
| public Ball(String color, int number) { | ||
| this.color = color; | ||
| this.number = number; | ||
| } | ||
|
|
||
|
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. Redundant empty line between the constructor and the overridden method — this violates the checklist: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature." Remove the blank line. 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 violates the checklist requirement: "Remove the extra blank lines after the class declaration, before the constructor, and between the constructor and |
||
| @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; | ||
|
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 between the |
||
|
|
||
|
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's an extra blank line between the |
||
| public class ColorSupplier { | ||
| private static 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. The |
||
|
|
||
|
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 an extra blank line directly after the |
||
| public String getRandomColor() { | ||
| return null; | ||
| return Colors.values()[RANDOM.nextInt(Colors.values().length)].name(); | ||
|
Comment on lines
+3
to
+9
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 contains redundant empty lines. This violates the checklist item: "Please don't add redundant empty lines to your code. We don't need them after class declaration or method signature." Remove the unnecessary blank lines between package/import, before/after the field declaration, and at the end of the file so the class/method signatures are directly followed by code. |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package core.basesyntax; | ||
|
|
||
| public enum Colors { | ||
| RED, | ||
| GREEN, | ||
| BLUE, | ||
| YELLOW, | ||
| BLACK, | ||
| WHITE | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package core.basesyntax; | ||
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Lottery { | ||
| private static final int MX = 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. This violates the checklist item: "Don't forget how to name constants according to style guide (the same with naming of enum values)". The constant |
||
| private Random randomNumber = new Random(); | ||
| private ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
Comment on lines
+7
to
+8
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. Consider making these fields immutable to better express intent: |
||
|
|
||
| public Ball getRandomBall() { | ||
| return new Ball(colorSupplier.getRandomColor(), randomNumber.nextInt(MX + 1)); | ||
| } | ||
| } | ||
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 the checklist requirement: "All magic numbers in your code should be constants." Specifically, the previous instruction also required: "The literal
3used as the number of balls in the loop is a magic number and must be replaced with a named constant (for example,private static final int NUMBER_OF_BALLS = 3;and then useNUMBER_OF_BALLSin theforloop)." Replacefinal int NM = 3;with a descriptive class-level constant (e.g.private static final int NUMBER_OF_BALLS = 3;) and use it in theforloop.