-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
done #1735
base: master
Are you sure you want to change the base?
done #1735
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
private Colors color; | ||
private int number; | ||
|
||
public void setColor(Colors color) { | ||
this.color = color; | ||
} | ||
|
||
public String getColor() { | ||
return this.color.toString(); | ||
} | ||
|
||
public void setNumber(int number) { | ||
this.number = number; | ||
} | ||
|
||
public int getNumber() { | ||
return this.number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Ball [Color = " + color + ", Number = " + number + "]"; | ||
} | ||
} |
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; | ||
public Colors getRandomColor() { | ||
Random random = new Random(); | ||
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. random should be a private final class level variable |
||
int index = random.nextInt(Colors.values().length); | ||
return Colors.values()[index]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,10 @@ | ||||||
package core.basesyntax; | ||||||
|
||||||
public enum Colors { | ||||||
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.
Suggested change
|
||||||
RED, | ||||||
BLUE, | ||||||
GREEN, | ||||||
YELLOW, | ||||||
ORANGE, | ||||||
BLACK | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
public Ball getRandomBall() { | ||
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. Random and ColorSuplier should be a private final class level variable |
||
Ball ball = new Ball(); | ||
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. also, you can create a constructor with parameters for the Ball model and simplify your solution. |
||
ColorSupplier colorSupplier = new ColorSupplier(); // Create a ColorSupplier object | ||
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. remove redundant comment |
||
Colors randomColor = colorSupplier.getRandomColor(); | ||
ball.setColor(randomColor); | ||
int randomValue = new Random().nextInt(100); | ||
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. make magic number constant field |
||
ball.setNumber(randomValue); | ||
return ball; | ||
} | ||
} |
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.
Make 3 constant field