Skip to content

Conversation

aunkerrr
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 Application and Ball classes! 😊 Your use of the enum's name() method in the Ball class is spot-on for getting the color representation. As suggested, consider using loops to handle repetitive tasks in the future to make your code even more efficient and maintainable. Keep up the good work! 👍

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

Comment on lines 6 to 12
Ball ball1 = lottery.getRandomBall();
Ball ball2 = lottery.getRandomBall();
Ball ball3 = lottery.getRandomBall();

System.out.println(ball1);
System.out.println(ball2);
System.out.println(ball3);

Choose a reason for hiding this comment

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

Instead of creating multiple Ball instances separately, consider using a for-loop to create and print the balls. This will make the code more concise and easier to maintain if you need to generate a different number of balls in the future. Refer to the checklist about using a for loop for creating several objects of the same class.

public String getRandomColor() {
return null;
public Color getRandomColor() {
Random random = new Random();

Choose a reason for hiding this comment

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

Creating a new instance of 'Random' each time the method is called can be inefficient if the method is called multiple times. Consider making 'random' a class-level instance variable.

Choose a reason for hiding this comment

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

fix comment


import java.util.Random;

class Lottery {

Choose a reason for hiding this comment

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

Classes must have access modifiers; otherwise, the default will be used, which isn't a good practice. Consider adding an access modifier to the Lottery class.


class Lottery {
public Ball getRandomBall() {
Random random = new Random();

Choose a reason for hiding this comment

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

The instance of Random could be a class-level field instead of being created every time the 'getRandomBall' method is called. This would be more efficient as it avoids unnecessary object creation.

Choose a reason for hiding this comment

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

fix comment

class Lottery {
public Ball getRandomBall() {
Random random = new Random();
Color color = new ColorSupplier().getRandomColor();

Choose a reason for hiding this comment

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

Creating a new instance of ColorSupplier every time may be inefficient if the getRandomColor method does not depend on instance state. Consider making ColorSupplier a class-level field or its method static if there's no state.

Choose a reason for hiding this comment

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

fix comment

public Ball getRandomBall() {
Random random = new Random();
Color color = new ColorSupplier().getRandomColor();
int number = random.nextInt(101);

Choose a reason for hiding this comment

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

Magic numbers should be avoided and replaced with named constants for better code readability. Consider creating a constant for the number 101, giving it a meaningful name that explains what it represents.

Choose a reason for hiding this comment

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

fix comment

Choose a reason for hiding this comment

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

not fixed

public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
Lottery lottery = new Lottery();
Ball ball1 = lottery.getRandomBall();

Choose a reason for hiding this comment

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

Please use for loop.
if you have 100 balls, you won't need to create 100 lines of code

package core.basesyntax;

public class Ball {
private Color color;

Choose a reason for hiding this comment

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

Suggested change
private Color color;
private String color;

package core.basesyntax;

public enum Color {
RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, WHITE

Choose a reason for hiding this comment

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

Suggested change
RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, WHITE
RED,
GREEN,
BLUE,
YELLOW,
ORANGE,
BLACK,
WHITE

Choose a reason for hiding this comment

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

not fixed

public class ColorSupplier {
public String getRandomColor() {
return null;
public Color getRandomColor() {

Choose a reason for hiding this comment

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

Suggested change
public Color getRandomColor() {
public String getRandomColor() {

Choose a reason for hiding this comment

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

not fixed

public String getRandomColor() {
return null;
public Color getRandomColor() {
Random random = new Random();

Choose a reason for hiding this comment

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

fix comment

public Ball getRandomBall() {
Random random = new Random();
Color color = new ColorSupplier().getRandomColor();
int number = random.nextInt(101);

Choose a reason for hiding this comment

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

fix comment


class Lottery {
public Ball getRandomBall() {
Random random = new Random();

Choose a reason for hiding this comment

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

fix comment

class Lottery {
public Ball getRandomBall() {
Random random = new Random();
Color color = new ColorSupplier().getRandomColor();

Choose a reason for hiding this comment

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

fix comment


Lottery lottery = new Lottery();

for (int i = 0; i < 3; i++) {

Choose a reason for hiding this comment

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

3 is a magic number, create constant

Comment on lines 9 to 10
Ball ball = lottery.getRandomBall();
System.out.println(ball);

Choose a reason for hiding this comment

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

Suggested change
Ball ball = lottery.getRandomBall();
System.out.println(ball);
System.out.println(lottery.getRandomBall());

private String color;
private int number;

public Ball(Color color, int number) {

Choose a reason for hiding this comment

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

Suggested change
public Ball(Color color, int number) {
public Ball(String color, int number) {


public Ball(Color color, int number) {
this.number = number;
this.color = String.valueOf(color);

Choose a reason for hiding this comment

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

Suggested change
this.color = String.valueOf(color);
this.color = color;

public class ColorSupplier {
public String getRandomColor() {
return null;
public Color getRandomColor() {

Choose a reason for hiding this comment

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

not fixed

public Ball getRandomBall() {
Random random = new Random();
Color color = new ColorSupplier().getRandomColor();
int number = random.nextInt(101);

Choose a reason for hiding this comment

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

not fixed


class Lottery {
private Random random = new Random();
private Color color = new ColorSupplier().getRandomColor();

Choose a reason for hiding this comment

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

Suggested change
private Color color = new ColorSupplier().getRandomColor();
private ColorSupplier colorSupplier = new ColorSupplier();


public Ball getRandomBall() {
int number = random.nextInt(101);
return new Ball(color, number);

Choose a reason for hiding this comment

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

Suggested change
return new Ball(color, number);
String randomColor = colorSupplier.getRandomColor();
return new Ball(randomColor, number);

@aunkerrr aunkerrr requested a review from Elena-Bruyako August 25, 2024 22:21
Comment on lines 8 to 10
public Color getRandomColor() {
Color[] colors = Color.values();
return colors[random.nextInt(colors.length)];

Choose a reason for hiding this comment

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

return in String type

Comment on lines 8 to 10

public Ball getRandomBall() {
int number = random.nextInt(101);

Choose a reason for hiding this comment

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

Save to constant


public Ball getRandomBall() {
int number = random.nextInt(maxValue);
String randomColor = String.valueOf(colorSupplier.getRandomColor());

Choose a reason for hiding this comment

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

Suggested change
String randomColor = String.valueOf(colorSupplier.getRandomColor());
String randomColor = colorSupplier.getRandomColor();

public class Application {
public static void main(String[] args) {
// create three balls using class Lottery and print information about them in console
int ballsNumber = 3;

Choose a reason for hiding this comment

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

it should be constant

package core.basesyntax;

public enum Color {
RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, WHITE

Choose a reason for hiding this comment

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

not fixed


public String getRandomColor() {
return null;
Color[] colors = Color.values();

Choose a reason for hiding this comment

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

you can create it as class-level variable


import java.util.Random;

class Lottery {

Choose a reason for hiding this comment

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

Suggested change
class Lottery {
public class Lottery {

import java.util.Random;

class Lottery {
private int maxValue = 101;

Choose a reason for hiding this comment

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

make it constant

@aunkerrr aunkerrr requested a review from Elena-Bruyako August 29, 2024 00:07
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