Skip to content
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

maked lottery task #1693

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

DanTeslenko
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.


Hello! 😊 You've done a great job implementing the core functionality of the task, and your code is mostly on point. However, there are a few critical issues that need to be addressed before we can approve the pull request:

  1. Access Modifiers: The Ball class fields lack explicit access modifiers. It's important to define these to ensure encapsulation and maintainability of your code.

  2. Magic Numbers: In the Lottery class, the number 100 is used directly. It's best practice to define this as a constant to improve code readability and maintainability.

  3. Enum String Representation: In the ColorSupplier class, using toString() for enums can lead to unexpected results if overridden. Please use name() instead for a more reliable approach.

  4. Unnecessary Instance Creation: Creating a new ColorSupplier instance every time getRandomBall() is called is inefficient. Consider creating a single instance and reusing it.

These changes are essential to ensure the code is robust and adheres to best practices. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀

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

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

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

Choose a reason for hiding this comment

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

Instead of using toString(), use the name() method to get the string representation of the enum constants. This is a more reliable approach as toString() can be overridden, potentially leading to unexpected results.

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.

Great job on implementing the main functionality of the Application class and addressing some of the previous review comments! 🎉 Your code is on the right track, but there are a few important areas to focus on for improvement:

  1. Access Modifiers: Ensure all classes, fields, constructors, and methods have explicit access modifiers. Specifically, the getRandomColor method in the ColorSupplier class should have an access modifier.

  2. Magic Numbers: The Lottery class uses the number 100 directly for generating random numbers. Define this as a constant to enhance readability and maintainability.

  3. Instance Creation: Avoid creating new instances unnecessarily. The ColorSupplier class should reuse a single Random instance, and the Lottery class should not create a new ColorSupplier instance every time getRandomBall() is called.

  4. Static Final Constants: The bound variable is correctly defined as static, but it should also be final to indicate it's a constant.

  5. Initialization: The colorSupplier field should be initialized either in the constructor or directly in the field declaration to prevent NullPointerException.

These improvements will help you write cleaner and more efficient code. Keep up the good work, and make sure to address these issues in future iterations to enhance your coding skills! 🚀

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


public class Lottery {
private static int bound = 100;
private ColorSupplier colorSupplier;

Choose a reason for hiding this comment

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

The colorSupplier field is declared but not initialized. Consider initializing it in the constructor or directly in the field declaration to avoid potential NullPointerException when calling getRandomColor().

import java.util.Random;

public class Lottery {
private static int bound = 100;

Choose a reason for hiding this comment

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

The bound variable is defined as a static field, which is good for a constant. However, it should be declared as final to indicate that it is a constant value and should not be changed.

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