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

solution #1753

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

solution #1753

wants to merge 2 commits into from

Conversation

IGORECHEKST
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, and your code mostly aligns with the task requirements. However, there are a few important improvements needed before we can approve the pull request:

  1. Use a Loop for Object Creation: In the Application.java file, instead of manually creating three instances of the Lottery class, you should use a loop to create and print the results. This will make your code more concise and easier to maintain.

  2. Avoid Multiple Instances: You don't need to create multiple instances of the Lottery class. You can create one instance and use it to generate all the random balls.

  3. Magic Numbers: Replace the magic number 100 in the Lottery class with a constant for better readability and maintainability.

  4. Optimize Object Creation: In the Lottery class, avoid creating a new ColorSupplier instance each time getRandomBall() is called. Instead, create a single instance and reuse it.

These changes will enhance the efficiency and readability of your code. Keep up the great work, and feel free to reach out if you have any questions! 🚀

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

Comment on lines 5 to 12
Lottery l1 = new Lottery();
System.out.println(l1.getRandomBall());

Lottery l2 = new Lottery();
System.out.println(l2.getRandomBall());

Lottery l3 = new Lottery();
System.out.println(l3.getRandomBall());

Choose a reason for hiding this comment

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

Instead of creating three separate instances of Lottery and calling getRandomBall() on each, consider using a loop to achieve the same result. This approach is recommended in the checklist: 'Use for loop for creating several objects of the same class'.

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 task requirements! 🎉 Your code is well-structured, and you've made good progress. Here are a few suggestions to enhance your code further:

  1. Lottery Class: Consider creating a single instance of Random and ColorSupplier as class members to avoid creating new instances each time getRandomBall() is called. This will improve efficiency.

  2. Application Class: Instead of creating a new Lottery instance in each loop iteration, create one outside the loop and reuse it.

  3. Magic Numbers: Replace the number 100 in the Lottery class with a constant for better readability.

These improvements will help you write more efficient and maintainable code. Keep up the good work and continue learning from these suggestions! 🚀

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

Comment on lines +5 to +6
for (int i = 0; i < 3; i++) {
System.out.println(new Lottery().getRandomBall());

Choose a reason for hiding this comment

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

Currently, a new instance of the Lottery class is created in each iteration of the loop. To optimize this, consider creating a single instance of the Lottery class outside the loop and reusing it. This will improve the efficiency of your code.

Comment on lines +6 to +7
public Colors getRandomColor() {
int index = 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.

To improve efficiency, consider creating a single instance of Random as a class member and reusing it in the getRandomColor method. This avoids creating a new Random object each time the method is called.

public class Lottery {
public Ball getRandomBall() {
Ball newBall = new Ball();
newBall.setNumber(new Random().nextInt(100));

Choose a reason for hiding this comment

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

Consider creating a single instance of Random as a class member and reusing it in the getRandomBall method. This avoids creating a new Random object each time the method is called.

public Ball getRandomBall() {
Ball newBall = new Ball();
newBall.setNumber(new Random().nextInt(100));
newBall.setColor(new ColorSupplier().getRandomColor());

Choose a reason for hiding this comment

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

Instead of creating a new ColorSupplier instance each time getRandomBall() is called, consider creating a single instance of ColorSupplier as a class member and reusing it. This will improve the efficiency of your code.

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