Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because several core task requirements are not yet met, which blocks the solution from being considered complete.
Critical issues to fix:
Balldesign and behavior:Ballcurrently extendsColorSupplierand does not have the requiredcolorandnumberfields; it also generates random values insidetoString(). The requirement is thatBallis a simple POJO with private fields (e.g.private Colors color; private int number;), a constructor to set them, andtoString()that returns those stored values (e.g. usingcolor.name()), not new random ones.LotteryAPI and return type: The task requirespublic Ball getRandomBall()that returns aBallobject; your code hasnewLottery()returning aString. You need to implementgetRandomBall()so it usesColorSupplier.getRandomColor()and aRandom(with a max of 100 via a constant) to construct and return aBall, not its string representation.Application.mainflow:mainmust create threeBallobjects usinglottery.getRandomBall()and print them. Right now it callslottery.newLottery()and prints the returnedString. Replace this with a loop that runs a named constant count (e.g.BALL_COUNT = 3) and on each iteration callsgetRandomBall()and prints theBall.
Style/checklist issues (after fixing logic): In both Ball and ColorSupplier, avoid creating a new Random in every method call ([CHECKLIST ITEM #4, #5]); instead, use a single class-level Random. Also remove redundant empty lines ([CHECKLIST ITEM #1]), avoid unnecessary temporary variables by returning directly where appropriate ([CHECKLIST ITEM #2]), and replace magic numbers like 101 and 3 with named constants ([CHECKLIST ITEM #9]). Once you address these points, your solution will better match both the functional requirements and the checklist guidelines—your Colors enum and basic random-color idea are on the right track, you just need to wire them into Ball, Lottery, and Application as specified.
✨ 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
|
|
||
| import java.util.Random; | ||
|
|
||
| public class Ball extends ColorSupplier { |
There was a problem hiding this comment.
This violates the requirement: "create a Ball class with the following fields: color and number and override the toString() method" . The class has no color or number fields and instead extends ColorSupplier. Ball should be a simple data class (POJO) that stores its color and number; it should not inherit from ColorSupplier.
| public class Ball extends ColorSupplier { | ||
|
|
||
| public int getRandomBallNumber() { | ||
| Random randomBallNumber = new Random(); |
There was a problem hiding this comment.
The method creates a new Random instance each call: Random randomBallNumber = new Random();. This conflicts with checklist guidance: "Don't create several instances of the same class if you can use only one instance for your purposes" and "Think about which variables should be local in the method and which should be class-level" . Consider using a single Random field or a shared supplier instance instead of instantiating in each method call.
|
|
||
| public int getRandomBallNumber() { | ||
| Random randomBallNumber = new Random(); | ||
| return randomBallNumber.nextInt(101); |
There was a problem hiding this comment.
This uses a magic literal: nextInt(101). This violates checklist item: "All magic numbers in your code should be constants." . Define a named constant (e.g. private static final int MAX_BALL_NUMBER = 100) and use it to compute the bound.
| public String toString() { | ||
| String number = String.valueOf(getRandomBallNumber()); | ||
| return "Ball number is: " + number + " and color is: " + getRandomColor(); |
There was a problem hiding this comment.
The toString() method generates random values on each call (getRandomBallNumber() and getRandomColor()) rather than returning the object's stored fields. According to the task description the Ball should store color and number and toString() should present those fields ("create a Ball class with the following fields: color and number and override the toString() method") . Move random generation out of toString() and use the instance fields inside toString().
|
|
||
| @Override | ||
| public String toString() { | ||
| String number = String.valueOf(getRandomBallNumber()); |
There was a problem hiding this comment.
This creates a temporary variable String number = String.valueOf(getRandomBallNumber()); which can be avoided. The checklist says: "Don't create temporary variables if you can directly return value from the method" . After fixing the class to have a number field, you can directly return the formatted string using that field.
| Lottery lottery = new Lottery(); | ||
|
|
||
| for (int i = 0; i < 3; i++) { | ||
| System.out.println(lottery.newLottery()); |
There was a problem hiding this comment.
This violates the requirement: "In the main() method, create three balls using the getRandomBall() method from the Lottery class." The code calls lottery.newLottery() and prints its String result instead of calling lottery.getRandomBall() to obtain three Ball objects and then printing those Ball instances.
| // create three balls using class Lottery and print information about them in console | ||
| Lottery lottery = new Lottery(); | ||
|
|
||
| for (int i = 0; i < 3; i++) { |
There was a problem hiding this comment.
This violates checklist item #9: "All magic numbers in your code should be constants." The loop uses the literal 3. Define a named constant (for example private static final int BALL_COUNT = 3) and use it in the for-loop instead of the magic number.
| package core.basesyntax; | ||
|
|
||
| public class Lottery { | ||
| public String newLottery() { |
There was a problem hiding this comment.
This violates the requirement: "Create a Lottery class with the getRandomBall() method, which will return the ball." The current method is named newLottery() and its signature returns String instead of Ball. Implement public Ball getRandomBall() that returns a Ball object constructed with random color and number (max 100) as specified in the description .
|
|
||
| public class Lottery { | ||
| public String newLottery() { | ||
| Ball randomBall = new Ball(); |
There was a problem hiding this comment.
This violates checklist item #2: "Don't create temporary variables if you can directly return value from the method". The local variable randomBall is unnecessary if your method builds and returns a Ball directly. Also, returning randomBall.toString() here is incorrect — the method should return the Ball object itself (see requirement) .
| public String newLottery() { | ||
| Ball randomBall = new Ball(); | ||
|
|
||
| return randomBall.toString(); |
There was a problem hiding this comment.
Returning randomBall.toString() makes the method return a String rather than a Ball. This breaks the required behavior: "getRandomBall() method should create a ball with a random color and a random number and return this ball from the method." Change the method to return the Ball instance (not its toString()), and move random generation into that getRandomBall() implementation as specified .
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there is still a functional requirement not fully met and several mandatory checklist items are violated. In Lottery.getRandomBall() you use random.nextInt(number) with number = 100, which only produces values 0–99; the task explicitly requires that the maximum possible random number for a ball be 100, so you need to adjust the bound (for example MAX_NUMBER + 1 or + 1 after nextInt) and store this in a private static final int MAX_NUMBER = 100 constant. In the same class, number, random, and the ColorSupplier field are public and non-final, which breaks encapsulation and conflicts with the checklist on access modifiers and constants; make them private (and final where appropriate) with proper constant naming. In ColorSupplier, you create a new Random and temporary variables every time getRandomColor() is called, which goes against the checklist on reusing instances and avoiding unnecessary temporaries; instead, keep a single private final Random random field and either return Colors.values()[...] directly or at least remove redundant variables. Across Application, Ball, Colors, Lottery, and ColorSupplier, there are also required style fixes: remove redundant blank lines, add the missing blank line after the package statement where Checkstyle demands it, replace the magic literal 3 in the loop with a named constant, and in Ball.toString() use color.name() and adjust the string concatenation operator placement. Once you fix these functional and checklist issues, your solution will satisfy both the task requirements and the style constraints, and the build should pass cleanly.
✨ 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
| public String getRandomColor() { | ||
| return null; | ||
| public Colors getRandomColor() { | ||
| Random random = new Random(); |
There was a problem hiding this comment.
This creates a new Random every time getRandomColor() is called. This violates CHECKLIST ITEM #4: "Don't create several instances of the same class if you can use only one instance for your purposes." and CHECKLIST ITEM #5: "Think about which variables should be local in the method and which should be class-level." Move Random to a private class-level field (e.g. private final Random random = new Random()) and reuse it.
| return null; | ||
| public Colors getRandomColor() { | ||
| Random random = new Random(); | ||
| Colors[] color = Colors.values(); |
There was a problem hiding this comment.
You create temporary variables Colors[] color and randomIndex here. This violates CHECKLIST ITEM #2: "Don't create temporary variables if you can directly return value from the method." Consider returning directly (for example: return Colors.values()[random.nextInt(Colors.values().length)];) or at least avoid the redundant randomIndex by using a single expression.
| public Colors getRandomColor() { | ||
| Random random = new Random(); | ||
| Colors[] color = Colors.values(); | ||
| int randomIndex = random.nextInt(color.length); |
There was a problem hiding this comment.
This violates CHECKLIST ITEM #2: "Don't create temporary variables if you can directly return value from the method." The separate randomIndex variable is unnecessary — compute the index inline or return directly.
| Random random = new Random(); | ||
| Colors[] color = Colors.values(); | ||
| int randomIndex = random.nextInt(color.length); | ||
|
|
There was a problem hiding this comment.
Redundant blank line inside the method. This violates CHECKLIST ITEM #1: "Please don't add redundant empty lines to your code. “We don't need them after class declaration or method signature.”" Remove the extra blank line(s) inside the class/method.
| public static void main(String[] args) { | ||
| // create three balls using class Lottery and print information about them in console | ||
| Lottery lottery = new Lottery(); | ||
|
|
There was a problem hiding this comment.
This file has a redundant empty line between the Lottery creation and the for-loop. This violates checklist item #1: "Please don't add redundant empty lines to your code. “We don't need them after class declaration or method signature.”" Remove the empty line to match the checklist.
| import java.util.Random; | ||
|
|
||
| public class Lottery { | ||
| public int number = 100; |
There was a problem hiding this comment.
Field number holds the magic number 100 but is not a constant and the field is public. This violates checklist item #9: "All magic numbers in your code should be constants." and checklist item #7: "Pay attention to access modifiers. “Classes, fields, constructors, methods must have access modifiers otherwise default will be used that isn't a good practice.”" Suggestion: private static final int MAX_NUMBER = 100;
|
|
||
| public class Lottery { | ||
| public int number = 100; | ||
| public Random random = new Random(); |
There was a problem hiding this comment.
Class-level Random is fine to keep, but its visibility should not be public. This violates checklist item #7: "Pay attention to access modifiers..." Make it private final Random random = new Random(); so it's encapsulated.
| public class Lottery { | ||
| public int number = 100; | ||
| public Random random = new Random(); | ||
| public ColorSupplier color = new ColorSupplier(); |
There was a problem hiding this comment.
The ColorSupplier instance should be encapsulated (not public). This violates checklist item #7: "Pay attention to access modifiers..." Make it private final ColorSupplier colorSupplier = new ColorSupplier(); and consider renaming the field to be more descriptive.
| public int number = 100; | ||
| public Random random = new Random(); | ||
| public ColorSupplier color = new ColorSupplier(); | ||
|
|
There was a problem hiding this comment.
Redundant empty line here. This violates checklist item #1: "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.
| public ColorSupplier color = new ColorSupplier(); | ||
|
|
||
| public Ball getRandomBall() { | ||
| return new Ball(color.getRandomColor(), random.nextInt(number)); |
There was a problem hiding this comment.
Functional/logic issue: random.nextInt(number) uses the bound stored in number (100). Random.nextInt(100) produces 0..99, so the maximum possible generated value is 99, not 100. This violates the requirement: "The maximum possible random number for the ball in getRandomBall() should be 100." Also this uses a non-constant bound (see checklist item #9). Fix: declare private static final int MAX_NUMBER = 100; and generate the value so 100 can appear (for example random.nextInt(MAX_NUMBER + 1) to get 0..100, or random.nextInt(MAX_NUMBER) + 1 to get 1..100) depending on the intended range.
…Supplier, line remove in Lottery
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving your solution as an educational override so you can keep progressing, but there are a few important style and checklist points to improve next.
You implemented the main functionality correctly: the Colors enum is well-defined, ColorSupplier returns random colors, Lottery generates random balls up to 100, and Application prints three balls using a loop – nice job covering all core requirements. The next step is to fix several style/checklist issues: in ColorSupplier you should use a single class-level private final Random random and avoid creating a new Random inside getRandomColor() on every call, and consider caching Colors.values() in a constant array [CHECKLIST ITEM #2, #5, #6]. In Lottery, replace the magic number 101 with a constant like private static final int MAX_NUMBER = 100 and use it in random.nextInt(MAX_NUMBER + 1), and make random and ColorSupplier fields private final [CHECKLIST ITEM #9]. In Application, replace the literal 3 in the loop with a named constant (for example NUMBER_OF_BALLS) and keep the formatting clean without extra blank lines [CHECKLIST ITEM #1, #9]. In Ball.toString(), use color.name() instead of color directly and adjust the string concatenation so it passes Checkstyle (no operator-wrap issues) [CHECKLIST ITEM #10].
There are also a few formatting issues reported by Checkstyle (missing blank line after package, redundant empty lines, and missing newline at end of file) – fixing these will make your code pass CI and match standard Java style [CHECKLIST ITEM #1]. Overall, you’ve done well with the core logic; focusing on constants, field modifiers, and formatting will help you write cleaner, more professional Java code going forward.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| public String getRandomColor() { | ||
| return null; | ||
| public Colors getRandomColor() { | ||
| Random random = new Random(); |
There was a problem hiding this comment.
This violates checklist item #2: "Don't create temporary variables if you can directly return value from the method" and checklist item #5: "Think about which variables should be local in the method and which should be class-level". You're creating new Random() on every call (Random random = new Random();). Instead, keep a single private final Random random = new Random(); field in the class and reuse it inside getRandomColor().
| public Colors getRandomColor() { | ||
| Random random = new Random(); | ||
|
|
||
| return Colors.values()[random.nextInt(Colors.values().length)]; |
There was a problem hiding this comment.
Consider caching Colors.values() in a named constant and using it with the class-level Random. For example: private static final Colors[] VALUES = Colors.values(); and then return VALUES[random.nextInt(VALUES.length)];. This follows checklist item #6: "Don't forget how to name constants according to style guide (the same with naming of enum values)" and avoids repeated calls to Colors.values().
| public String toString() { | ||
| return "Ball{" + | ||
| "color=" + color + | ||
| ", number=" + number + |
There was a problem hiding this comment.
This violates checklist item #10: "Use name() for getting String representation of enum constants; don't use toString() or String.valueOf() for that." In toString() you use color directly; use color.name() to get the enum constant's String name (for example: "Ball{color=" + color.name() + ", number=" + number + '}').
|
|
||
| public Ball(Colors color, int number) { | ||
| this.color = color; | ||
| this.number = number; | ||
| } | ||
|
|
||
| public Colors getColor() { | ||
| return color; | ||
| } | ||
|
|
||
| public void setColor(Colors color) { | ||
| this.color = color; | ||
| } | ||
|
|
||
| public int getNumber() { | ||
| return number; | ||
| } | ||
|
|
||
| public void setNumber(int number) { | ||
| this.number = number; | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Ball{" + | ||
| "color=" + color + | ||
| ", number=" + number + | ||
| '}'; | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
This violates checklist item #1: "Please don't add redundant empty lines to your code (e.g., after class declaration or method signature)." There are several redundant blank lines inside this class (for example around lines 5, 10, 14, 18, 22, 26, 35). Remove unnecessary empty lines to follow the style guideline.
| public static void main(String[] args) { | ||
| // create three balls using class Lottery and print information about them in console | ||
| Lottery lottery = new Lottery(); | ||
|
|
There was a problem hiding this comment.
This violates checklist item #1: "Please don't add redundant empty lines to your code (e.g., after class declaration or method signature)." Remove this redundant blank line inside main (it's not needed between the Lottery creation and the loop).
| // create three balls using class Lottery and print information about them in console | ||
| Lottery lottery = new Lottery(); | ||
|
|
||
| for (int i = 0; i < 3; i++) { |
There was a problem hiding this comment.
This violates checklist item #9: "All magic numbers in your code should be constants." Replace the literal 3 with a named constant (for example private static final int NUMBER_OF_BALLS = 3) and use that constant in the loop condition.
| package core.basesyntax; | ||
| import java.util.Random; | ||
| public class Lottery { | ||
| private int number = 101; |
There was a problem hiding this comment.
This violates checklist item #9: "All magic numbers in your code should be constants." You declare private int number = 101; — replace this magic literal with a properly named constant (for example private static final int MAX_NUMBER = 100) and use that constant for generating the random number so intent is clear and consistent.
| private Random random = new Random(); | ||
| private ColorSupplier color = new ColorSupplier(); |
There was a problem hiding this comment.
This violates the previous review correction: "In Lottery, make fields number, random, and the ColorSupplier field non-public (e.g., private) and use final where appropriate, and use proper constant naming for constants." The random and color fields are private but not final; make them private final and replace number with a private static final int MAX_NUMBER = 100 constant (use MAX_NUMBER naming).
| private ColorSupplier color = new ColorSupplier(); | ||
|
|
||
| public Ball getRandomBall() { | ||
| return new Ball(color.getRandomColor(), random.nextInt(number)); |
There was a problem hiding this comment.
getRandomBall() currently uses random.nextInt(number). To meet the task requirement that the maximum possible number is 100 and to follow the previous-review guidance, use the named constant and call random.nextInt(MAX_NUMBER + 1) (or equivalent) so that 100 can actually be produced and the code clearly documents the intended bound.
No description provided.