-
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
added solution #1281
base: master
Are you sure you want to change the base?
added solution #1281
Changes from 1 commit
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,30 @@ | ||
package core.basesyntax; | ||
|
||
public class Ball { | ||
|
||
private String color; | ||
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. 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. Use Enum Color that you created instead of regular String |
||
private int number; | ||
|
||
public String getColor() { | ||
return color; | ||
} | ||
|
||
public void setColor(String color) { | ||
this.color = color; | ||
} | ||
|
||
public int getNumber() { | ||
return number; | ||
} | ||
|
||
public void setNumber(int number) { | ||
this.number = number; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Ball: " | ||
+ "color - " + color | ||
+ "; number - " + number; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
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. |
||
Colors[] colors = Colors.values(); | ||
int indexOfRandom = random.nextInt(colors.length); | ||
return colors[indexOfRandom].toString(); | ||
} | ||
} |
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, | ||||||
WHITE, | ||||||
BLACK, | ||||||
GREEN, | ||||||
BLUE, | ||||||
ORANGE; | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package core.basesyntax; | ||
|
||
import java.util.Random; | ||
|
||
public class Lottery { | ||
|
||
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. Add access modifier for this method |
||
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. Move Ball, Color and Random instances creation out of this method - create them at the class level, so they can be reusable. Don't foerget access modifier for these fields once they are at the class level private Ball ball = new Ball(); public Ball getRandomBall() { |
||
ColorSupplier colorSupplier = new ColorSupplier(); | ||
String color = colorSupplier.getRandomColor(); | ||
ball.setColor(color); | ||
|
||
Random random = new Random(); | ||
int ballIndex = random.nextInt(101); | ||
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. |
||
ball.setNumber(ballIndex); | ||
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.
Lottery is lottery, Ball is ball. We need 1 Lottery and 3 Balls