Skip to content

Conversation

MarcinGryc
Copy link

No description provided.

@MarcinGryc MarcinGryc closed this Sep 13, 2025
Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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 like private static final int BALL_COUNT = 3; and iterating to create/print balls. Also remove the redundant empty line inside main.
  • Lottery.java: getRandomBall() is static, which violates “Don’t use static methods in your solution.” Make it an instance method and call it on a Lottery object. You also create new Random() and new 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 number 101 with a constant, e.g., private static final int MAX_NUMBER = 100; and use random.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 bound 3. Move Random to a reusable private field and use Colors.values().length (or a named constant) for the bound. Replace toString() with name() 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +6 to +8
Ball ball1 = lottery.getRandomBall();
Ball ball2 = lottery.getRandomBall();
Ball ball3 = lottery.getRandomBall();

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();

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();

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.

Comment on lines +2 to +17

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;
}

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;

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;

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() {

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();

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);

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();

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants