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

Hm jv lottery solution #1687

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

Conversation

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

Great job on implementing the lottery application! 🎉 The code meets the core requirements and functions as expected. While there are a few minor improvements suggested, such as using name() instead of toString() for enums, avoiding inheritance misuse, defining magic numbers as constants, and specifying access modifiers, these do not critically impact the functionality. Keep up the good work and consider these suggestions for future enhancements! 😊

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

Copy link

@ahoienko ahoienko left a comment

Choose a reason for hiding this comment

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

Very nice, left few comments, please check)

public class ColorSupplier {
public String getRandomColor() {
return null;
int index = new Random().nextInt(Color.values().length);
Copy link

Choose a reason for hiding this comment

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

It is better to create Random object on class level, because in current implementation you will create Random each time when method getRandomColor

Copy link

Choose a reason for hiding this comment

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

Same for Lottery class

public class Lottery extends ColorSupplier {
public Ball getRandomBall() {
Random random = new Random();
int value = random.nextInt(100);
Copy link

Choose a reason for hiding this comment

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

Magic number, please create a constant


import java.util.Random;

public class Lottery extends ColorSupplier {
Copy link

Choose a reason for hiding this comment

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

There is not reason to extend lottery from ColorSupplier, they are 2 totally different classes with different purpose, so they should not be in one hierarchy. So I suggest you to just create and object of ColorSupplier in Lottery and use getRandomColor method

@@ -2,6 +2,9 @@

public class Application {
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++) {
Copy link

Choose a reason for hiding this comment

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

3 is also magic number, please move it to constant

return null;
int index = random.nextInt(Color.values().length);
Color color = Color.values()[index];
return color.toString();

Choose a reason for hiding this comment

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

private static final int MAX_BALL_NUMBER = 100;
private final Random random = new Random();
private final ColorSupplier colorSupplier = new ColorSupplier();
private final Ball ball = new Ball();

Choose a reason for hiding this comment

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

Suggested change
private final Ball ball = new Ball();

Comment on lines 12 to 14
int value = random.nextInt(MAX_BALL_NUMBER);
ball.setColor(colorSupplier.getRandomColor());
ball.setNumber(value);

Choose a reason for hiding this comment

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

Suggested change
int value = random.nextInt(MAX_BALL_NUMBER);
ball.setColor(colorSupplier.getRandomColor());
ball.setNumber(value);
Ball ball = new Ball;
ball.setColor(colorSupplier.getRandomColor());
ball.setNumber(random.nextInt(MAX_BALL_NUMBER));

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

public class Application {
public static final int TOTAL_BALLS = 3;

Choose a reason for hiding this comment

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

Suggested change
public static final int TOTAL_BALLS = 3;
private static final int TOTAL_BALLS = 3;

… ColorSuppiler class. In the Application class, the access modifier in the TOTAL_BALLS field has been changed from public to private. Moved creation of the Ball object from the Lottery class level to the getRandomBall() method level
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.

4 participants