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

Create a simple lottery #1276

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

Create a simple lottery #1276

wants to merge 6 commits into from

Conversation

vfilimo
Copy link

@vfilimo vfilimo commented Dec 9, 2023

No description provided.

Copy link

@olekskov olekskov left a comment

Choose a reason for hiding this comment

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

Looks like not all files of project were commited or pushed

@vfilimo vfilimo requested a review from olekskov December 11, 2023 15:26
Comment on lines 7 to 21
public String getColor() {
return color;
}

public void setColor(String color) {
this.color = color;
}

public Integer getNumber() {
return number;
}

public void setNumber(Integer number) {
this.number = number;
}

Choose a reason for hiding this comment

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

Better use constructor for init Ball object

public class ColorSupplier {
public String getRandomColor() {
return null;
int inedex = 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.

image
About Random

Comment on lines 4 to 10
Red,
Blue,
Yellow,
White,
Green,
Orange,
Violet

Choose a reason for hiding this comment

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

Enum style

Comment on lines 8 to 10
Random random = new Random();
ball.setNumber(random.nextInt(100));
ColorSupplier supplier = new ColorSupplier();

Choose a reason for hiding this comment

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

image
Random and ColorSup.

Random random = new Random();
ball.setNumber(random.nextInt(100));
ColorSupplier supplier = new ColorSupplier();
ball.setColor(supplier.getRandomColor());

Choose a reason for hiding this comment

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

Init ball by constructor

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

Choose a reason for hiding this comment

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

Create Random in field of class, cause every invoke of method create new object!

Comment on lines 7 to 8
Random random = new Random();
ColorSupplier supplier = new ColorSupplier();

Choose a reason for hiding this comment

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

Same situation, save it in field

public Ball getRandomBall() {
Random random = new Random();
ColorSupplier supplier = new ColorSupplier();
int randomNumber = random.nextInt(100);

Choose a reason for hiding this comment

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

Magic number 100, what about constant?

@vfilimo vfilimo requested a review from Sanderfuck January 5, 2024 13:29
Comment on lines 9 to 10
int inedex = random.nextInt(Colors.values().length);
return Colors.values()[inedex].toString();
Copy link

Choose a reason for hiding this comment

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

index misspelled, don't use toString - revisit checklist, this issue is mentioned there

@@ -0,0 +1,11 @@
package core.basesyntax;

public enum Colors {
Copy link

Choose a reason for hiding this comment

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

Suggested change
public enum Colors {
public enum Color {

enum should be in singular

public class Lottery {
private Random random = new Random();
private ColorSupplier supplier = new ColorSupplier();
private int maxNumber = 100;
Copy link

Choose a reason for hiding this comment

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

make it constant - static final + MAX_NUMBER, and change to 101, because the value passed to randomizer is excluded itself

public Ball getRandomBall() {
int randomNumber = random.nextInt(maxNumber);
String randomColor = supplier.getRandomColor();
return new Ball(randomColor,randomNumber);
Copy link

Choose a reason for hiding this comment

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

we need space after comma, format your files in IDEA before committing (Ctrl Alt L)

@vfilimo vfilimo requested a review from okuzan January 5, 2024 14:41
Copy link

@olekskov olekskov left a comment

Choose a reason for hiding this comment

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

Good job

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