-
Notifications
You must be signed in to change notification settings - Fork 1.5k
1st solution #1911
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
1st solution #1911
Conversation
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.
Review Summary
I’m requesting changes because several explicit checklist requirements are violated, which are considered critical blockers for this task.
Critical issues to fix:
- Application.java: You create three balls with separate variables (lines with
ball1
,ball2
,ball3
). This violates “Use for loop for creating several objects of the same class” and introduces an implicit magic number. Fix by introducing a constant likeprivate static final int BALL_COUNT = 3;
and iterating to create/print balls. Also remove the redundant empty line insidemain
. - Lottery.java:
getRandomBall()
isstatic
, which violates “Don’t use static methods in your solution.” Make it an instance method and call it on aLottery
object. You also createnew Random()
andnew ColorSupplier()
inside the method each call — move these to reusable fields (private final Random random = new Random();
,private final ColorSupplier colorSupplier = new ColorSupplier();
). Replace the magic number101
with a constant, e.g.,private static final int MAX_NUMBER = 100;
and userandom.nextInt(MAX_NUMBER + 1)
to keep 0..100 inclusive. Remove redundant blank lines. - ColorSupplier.java: You instantiate
new Random()
inside the method and use a hard-coded bound3
. MoveRandom
to a reusable private field and useColors.values().length
(or a named constant) for the bound. ReplacetoString()
withname()
as required: e.g.,Colors.values()[index].name()
.
Minor but requested by checklist:
- Ball.java and Colors.java: Remove redundant empty lines. In Ball’s default constructor, replace the magic
-1
with a named constant (e.g.,DEFAULT_NUMBER
).
You’ve got the core functionality working — nice job. Addressing the above will align your solution with the task’s checklist and style requirements and should pass automated checks.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review
button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor
tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
Ball ball1 = lottery.getRandomBall(); | ||
Ball ball2 = lottery.getRandomBall(); | ||
Ball ball3 = 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 part creates three separate Ball variables instead of using a loop. This violates the checklist item: "Use for loop for creating several objects of the same class". Consider using a for
loop and a named constant for the number of balls.
@@ -2,6 +2,13 @@ | |||
|
|||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery lottery = new Lottery(); | |||
Ball ball1 = 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.
By creating three separate variables you implicitly use the number 3 instead of a named constant. This violates the checklist item: "All magic numbers in your code should be constants." Use a constant like private static final int BALL_COUNT = 3
and iterate over it.
Ball ball1 = lottery.getRandomBall(); | ||
Ball ball2 = lottery.getRandomBall(); | ||
Ball ball3 = 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.
There is an empty blank line between ball creation and printing. This is a redundant empty line — please follow the checklist: "Please don't add redundant empty lines to your code." Remove the blank line to keep code compact.
|
||
public class Ball { | ||
private String color; | ||
private int number; | ||
|
||
public Ball() | ||
{ | ||
this.color = ""; | ||
this.number = -1; | ||
} | ||
public Ball(String col, int num) | ||
{ | ||
this.color = col; | ||
this.number = num; | ||
} | ||
|
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: "Please don't add redundant empty lines to your code." Remove redundant blank lines (for example lines 2, 6 and 17) so the class and its members appear compactly. See checklist guidance.
public Ball() | ||
{ | ||
this.color = ""; | ||
this.number = -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 checklist item: "All magic numbers in your code should be constants." The default constructor sets this.number = -1;
(line 10). Consider replacing the literal with a named constant, e.g. private static final int DEFAULT_NUMBER = -1;
and use that constant here.
@@ -0,0 +1,14 @@ | |||
package core.basesyntax; | |||
|
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: "Please don't add redundant empty lines to your code." Remove redundant blank lines (e.g., this blank line) so class and method declarations are not separated by extra empty lines. See checklist guidance.
import java.util.Random; | ||
|
||
public class Lottery { | ||
public static Ball 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: "Don't use static methods in your solution" — business logic should be an instance method. Make getRandomBall()
an instance method (remove static
) and call it on a Lottery
instance. See checklist and current implementation.
|
||
public class Lottery { | ||
public static Ball getRandomBall() { | ||
Random random = new Random(); |
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: "Don't create several instances of the same class if you can use only one instance for your purposes" and the related guidance: "Think about which variables should be local in the method and which should be class-level". You're creating a new Random
every call; make a private final Random random = new Random();
field and reuse it. See checklist.
public class Lottery { | ||
public static Ball getRandomBall() { | ||
Random random = new Random(); | ||
int number = random.nextInt(101); |
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: "All magic numbers in your code should be constants." The literal 101
is used here. Introduce a named constant such as private static final int MAX_NUMBER = 100
and use it (e.g., random.nextInt(MAX_NUMBER + 1)
for inclusive 0..100). Also note the task requirement that the maximum possible number should be 100.
Random random = new Random(); | ||
int number = random.nextInt(101); | ||
|
||
ColorSupplier color = new ColorSupplier(); |
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: "Don't create several instances of the same class if you can use only one instance for your purposes" — instantiating new ColorSupplier()
on each call is unnecessary. Make a single private final ColorSupplier colorSupplier = new ColorSupplier()
field and reuse it. Also consider "Think about which variables should be local..." for placement.
No description provided.