Skip to content

Conversation

@user1997krzysiek
Copy link

No description provided.

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 core requirements are not met and they block correct functionality.

Critical issues to fix:

  • In Ball.java: color is a String, but it must be the enum type (e.g., private Color color;). Update the constructor and toString() to use color.name() [CHECKLIST ITEM #9].
  • In ColorSupplier.java: getRandomColor() must return Color, not String. Also return directly from Color.values()[random.nextInt(Color.values().length)] to avoid a temporary variable [CHECKLIST ITEM #2].
  • In Lottery.java: replace the mutable magic number with a constant private static final int MAX_NUMBER = 100; and generate a number that includes 100 (e.g., random.nextInt(MAX_NUMBER) + 1) so 100 is reachable [CHECKLIST ITEM #8].
  • In Application.java: replace the loop’s magic number 3 with a named constant (e.g., private static final int BALL_COUNT = 3) and use it in the for-loop [CHECKLIST ITEM #8].
  • Ensure all required files/classes are present and wired together: Ball, ColorSupplier, Lottery, Color enum, and the main method creating and printing three balls using a single Lottery instance and a for-loop.

Minor improvements:

  • Mark reusable fields like Random and ColorSupplier as final where appropriate.

You’ve got a good structure started (enum present, single Lottery instance, for-loop in main). Once the above blockers are fixed, the solution should meet the checklist.


✨ 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

public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery lottery = new Lottery();
for (int i = 0; i < 3; i++) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses a magic number 3 for the loop count which violates checklist item #8: "Replace any magic numbers (such as 100 or counts like 3) with named constants where appropriate [CHECKLIST ITEM #8]." Consider introducing a named constant (e.g., private static final int BALL_COUNT = 3) and using it in the loop to replace the literal 3. Also name constants in UPPER_SNAKE_CASE and provide an explicit access modifier.

package core.basesyntax;

public class Ball {
private String color;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This violates the requirement: "Ball class: Fields: color (type should align with the color enum), number (int)." The color field is declared as String. Change the field to use the enum type (for example private Color color;), and update the constructor parameter and assignments accordingly so Ball stores the enum value instead of a String.


@Override
public String toString() {
return "this is ball, color " + color + ", number " + number;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After you change color to the enum type, update toString() to use the enum's name. The checklist requires: "Use enum.name() to get String representation of enum constants if needed; do not rely on enum.toString() for representing enum constants [CHECKLIST ITEM #9]." For example: return "this is ball, color " + color.name() + ", number " + number;

@@ -0,0 +1,7 @@
package core.basesyntax;

public enum Color {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This submission only includes the Color enum. The overall task requires additional classes and behaviors that are not present. This violates the following required checklist items (quote from the task description):

  • "Implement a Ball class with fields: color and number."
  • "Implement a ColorSupplier class with a method getRandomColor() that returns a random enum color value using java.util.Random."
  • "Implement a Lottery class with a method getRandomBall() that: Creates a Ball with a random color (obtained via ColorSupplier.getRandomColor()). Assigns a random number to the ball, with the maximum possible number being 100. Returns the created Ball."
  • "In the main() method: Create three Ball objects using Lottery.getRandomBall(). Print information about the three balls to the console (via Ball.toString())."

Additionally, until those files are provided, the following checklist requirements cannot be verified and therefore are effectively violated by omission:

  • "Avoid static methods in the solution; use instances to call methods [CHECKLIST ITEM Lottery solution #3]."
  • "Avoid creating several instances of the same class when one instance suffices (e.g., reuse Lottery and ColorSupplier where applicable) [CHECKLIST ITEM Wrote an assignment jv-lottery. #4]."
  • "Use a for loop to create multiple objects of the same class when generating multiple balls (3 balls in main) [CHECKLIST ITEM My hw #7]."
  • "Replace any magic numbers (such as 100 or counts like 3) with named constants where appropriate [CHECKLIST ITEM Hw jv oop lotery #8]."
  • "Use enum.name() to get String representation of enum constants if needed; do not rely on enum.toString() for representing enum constants [CHECKLIST ITEM Jv lottery #9]."

Please add/upload the missing source files (Ball, ColorSupplier, Lottery, and the class containing main) implementing the quoted checklist items so I can perform a full checklist-based review.


public String getRandomColor() {
return null;
Color[] colors = Color.values();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This creates a temporary local variable colors but the checklist requires avoiding unnecessary temporary variables: "Avoid temporary variables if direct return is possible [CHECKLIST ITEM #2]". You can return directly from the values() array, for example: return Color.values()[random.nextInt(Color.values().length)];

public String getRandomColor() {
return null;
Color[] colors = Color.values();
return colors[random.nextInt(colors.length)].name();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method currently returns colors[...].name() — i.e., a String. This violates the requirement: "Method: getRandomColor() returns a randomly selected enum constant from the color enum using Random, based on enum values().length." You should change the method to return the enum type Color (e.g., public Color getRandomColor()) and return the enum constant itself (without calling .name()).

import java.util.Random;

public class Lottery {
private int number = 100;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses a magic number stored in a mutable field. Replace it with a named constant in UPPER_SNAKE_CASE and make it static final. This violates checklist requirements: "Replace any magic numbers (such as 100 or counts like 3) with named constants where appropriate [CHECKLIST ITEM #8]." and "Name constants in UPPER_SNAKE_CASE (e.g., MAX_NUMBER = 100; BALL_COUNT = 3) [CHECKLIST ITEM #6 and #8]."

Suggestion: private static final int MAX_NUMBER = 100;

private ColorSupplier colorSupplier = new ColorSupplier();

public Ball getRandomBall() {
return new Ball(colorSupplier.getRandomColor(), random.nextInt(number));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using random.nextInt(number) with number == 100 produces values 0..99, so 100 can never occur. This violates the requirement: "The random number’s maximum possible value must be 100 (ensure correct bounds when using Random)."

Suggestion: use the named constant and include 100 in the range, e.g. random.nextInt(MAX_NUMBER) + 1 (if you want 1..100) or random.nextInt(MAX_NUMBER + 1) (if you want 0..100). Ensure the chosen range matches the task interpretation that 100 must be reachable.

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

Great job addressing the previous feedback! The code is much cleaner. However, changes are needed because there is a critical bug in the Lottery class that violates a core requirement. The getRandomBall() method uses random.nextInt(100), which generates numbers in the range [0, 99], but the task requires the number to be up to and including 100. Please adjust the argument to nextInt to ensure 100 is a possible outcome. Also, as a good practice, consider making the random and colorSupplier fields final since they are initialized once and never changed. Once the number generation is fixed, your solution will be ready!


✨ 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 7 to 8
private Random random = new Random();
private ColorSupplier colorSupplier = new ColorSupplier();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are initialized once in the constructor and never reassigned. It's good practice to declare them as final to ensure they cannot be changed later.

private ColorSupplier colorSupplier = new ColorSupplier();

public Ball getRandomBall() {
return new Ball(colorSupplier.getRandomColor(), random.nextInt(MAX_NUMBER));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method random.nextInt(100) generates a number in the range from 0 (inclusive) to 100 (exclusive), meaning the maximum number generated will be 99. The requirement is to generate a number up to and including 100. You need to adjust the argument to include 100 in the possible outcomes, for example, by using MAX_NUMBER + 1.

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

Excellent work! You've done a fantastic job addressing the previous feedback. The random number generation is now working correctly, and making the fields final is a great improvement that enhances the robustness of your code. Your solution is clean, well-structured, and fully meets all the task requirements. I am happy to approve your submission. Keep up the great work!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

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