-
Notifications
You must be signed in to change notification settings - Fork 1.5k
implement lottery ball generation logic #1891
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,18 @@ | ||
package core.basesyntax; | ||
|
||
public class Application { | ||
private static final int BALL_COUNT = 3; | ||
|
||
public static void main(String[] args) { | ||
// create three balls using class Lottery and print information about them in console | ||
Lottery lottery = new Lottery(); | ||
Ball[] balls = new Ball[BALL_COUNT]; | ||
|
||
for (int i = 0; i < balls.length; i++) { | ||
balls[i] = lottery.getRandomBall(); | ||
} | ||
|
||
for (Ball ball: balls) { | ||
System.out.println(ball.toString()); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package core.basesyntax; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration. |
||
public class Ball { | ||
private final Color color; | ||
private final int number; | ||
|
||
public Ball(Color color, int number) { | ||
this.color = color; | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.color.name() + " " + "ball" + " " | ||
+ "with number" + " " + this.number; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package core.basesyntax; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the package declaration. |
||
public enum Color { | ||
RED, | ||
BLUE, | ||
GREEN, | ||
WHITE, | ||
BLACK | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
package core.basesyntax; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration. |
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
private final Random random = new Random(); | ||
|
||
public Color getRandomColor() { | ||
return Color.values()[this.random.nextInt(Color.values().length)]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package core.basesyntax; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration. |
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
private static final int MAX_BALL_NUMBER = 100; | ||
|
||
private final Random random = new Random(); | ||
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
|
||
public Ball getRandomBall() { | ||
return new Ball( | ||
this.colorSupplier.getRandomColor(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This violates the requirement: "The Ball class must have a constructor that sets both color and number." and "Create an enum with different colors." The Ball constructor should accept the Color enum, not a String. Ensure that getRandomColor() returns Color and Ball accepts Color as its color field. |
||
this.random.nextInt(MAX_BALL_NUMBER) + 1 | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This violates checklist item: "Avoid redundant empty lines after class declarations or method signatures." There is an unnecessary empty line after the class declaration.