Skip to content

Add lottery: Ball, Color enum, ColorSupplier, Lottery and main test#1997

Open
chupa-ilona wants to merge 20 commits intomate-academy:masterfrom
chupa-ilona:master
Open

Add lottery: Ball, Color enum, ColorSupplier, Lottery and main test#1997
chupa-ilona wants to merge 20 commits intomate-academy:masterfrom
chupa-ilona:master

Conversation

@chupa-ilona
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

Great job implementing the core logic! The program works correctly. However, some changes are needed to meet the project's coding standards before this can be approved. Please address the following checklist violations:

  • In ColorSupplier.java and Lottery.java, you are creating new Random and ColorSupplier objects on every method call. It's more efficient to create these as private fields and reuse the same instance. [CHECKLIST ITEM #4]
  • The numbers 3 in Application.java and 100 in Lottery.java are 'magic numbers'. Please declare them as named constants (e.g., private static final int MAX_BALL_NUMBER = 100;). [CHECKLIST ITEM #9]
  • Avoid creating temporary variables when you can return a value directly from a method, for example in Lottery.java and ColorSupplier.java. [CHECKLIST ITEM #2]
  • Use the .name() method instead of .toString() for getting the string value of an enum. [CHECKLIST ITEM #10]

Addressing these points will significantly improve your code's quality and adherence to best practices.


✨ 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 class ColorSupplier {
public String getRandomColor() {
return null;
Colors rand_color = Colors.values()[new Random().nextInt(Colors.values().length)];

Choose a reason for hiding this comment

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

This violates checklist item #4: 'Don't create several instances of the same class if you can use only one instance for your purposes'. A new Random() object is created with every method call. It is more efficient to create a single Random instance as a private field of the ColorSupplier class.

public class ColorSupplier {
public String getRandomColor() {
return null;
Colors rand_color = Colors.values()[new Random().nextInt(Colors.values().length)];

Choose a reason for hiding this comment

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

This line introduces a temporary variable rand_color, which violates checklist item #2: 'Don't create temporary variables if you can directly return value from the method'. The value could be returned directly.

public String getRandomColor() {
return null;
Colors rand_color = Colors.values()[new Random().nextInt(Colors.values().length)];
return rand_color.toString();

Choose a reason for hiding this comment

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

This violates checklist item #10: 'Use name() for getting String representation of enum constants'. The name() method should be used instead of toString() to get the string representation of an enum constant.


public class Lottery {
public Ball getRandomBall(){
Ball ball = new Ball(new ColorSupplier().getRandomColor(),

Choose a reason for hiding this comment

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

This violates checklist item #4: 'Don't create several instances of the same class if you can use only one instance for your purposes'. A new ColorSupplier object is created on every call to getRandomBall(). It's more efficient to make ColorSupplier a private field of the Lottery class and initialize it once.

public class Lottery {
public Ball getRandomBall(){
Ball ball = new Ball(new ColorSupplier().getRandomColor(),
new Random().nextInt(100) + 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 #9: 'All magic numbers in your code should be constants.' The number 100 should be declared as a named constant to improve readability and maintainability, for example private static final int MAX_BALL_NUMBER = 100;.

public class Lottery {
public Ball getRandomBall(){
Ball ball = new Ball(new ColorSupplier().getRandomColor(),
new Random().nextInt(100) + 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 #4: 'Don't create several instances of the same class if you can use only one instance for your purposes'. Creating a new Random object each time the method is called is inefficient. It's better practice to create a single Random instance as a private field within the Lottery class.

Comment on lines +7 to +9
Ball ball = new Ball(new ColorSupplier().getRandomColor(),
new Random().nextInt(100) + 1);
return ball;

Choose a reason for hiding this comment

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

This violates checklist item #2: 'Don't create temporary variables if you can directly return value from the method'. You can create and return the Ball object in a single line, like return new Ball(...).

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 progress on this task! You've successfully addressed almost all the feedback from the previous review, and your code is very close to being perfect.

However, one important issue from the last review remains. In src/main/java/core/basesyntax/Application.java, the number 3 is still used as a 'magic number'. This violates a core requirement to declare all such numbers as constants for better readability and maintainability [CHECKLIST ITEM #9].

Please declare it as a named constant, for example:
private static final int BALLS_COUNT = 3;

Once you make this small correction, your solution will be ready for approval. Keep up the great work!


✨ 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

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 successfully addressed the feedback from the previous review, and the code is now in great shape. Your solution correctly implements all functional requirements and adheres to the specified coding standards, especially with the great use of constants for all magic numbers. I am gladly approving your solution, keep up the fantastic 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