Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/main/java/core/basesyntax/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

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();
String[] balls = new String[3];
for (int i = 0; i < balls.length; i++) {
balls[i] = lottery.getRandomBall();
System.out.println(balls[i]);
}
System.out.println("Done");
}
}
6 changes: 5 additions & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package core.basesyntax;

import java.util.Random;

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

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 for every method call is inefficient. Consider creating a single Random instance as a class field and reusing it.

DifferentColors ballColor = DifferentColors.values()[index];
return ballColor.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(), it's better to use name() for getting the String representation of enum constants to avoid issues if toString() is overridden.

}
}
Loading