-
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
the ball lottery was created #1689
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||||||||||
package mate.academy; | ||||||||||||||
|
||||||||||||||
import mate.academy.model.Ball; | ||||||||||||||
import mate.academy.supplier.Lottery; | ||||||||||||||
|
||||||||||||||
public class Application { | ||||||||||||||
private static final int NUMBER_OF_BALLS = 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[NUMBER_OF_BALLS]; | ||||||||||||||
for (int i = 0; i < balls.length; i++) { | ||||||||||||||
balls[i] = lottery.getRandomBall(); | ||||||||||||||
System.out.println(balls[i].toString()); | ||||||||||||||
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
|
||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,35 @@ | ||||||||||||||||||||||||||||||
package mate.academy.model; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public class Ball { | ||||||||||||||||||||||||||||||
private Color color; | ||||||||||||||||||||||||||||||
private int number; | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public Ball(Color color, int number) { | ||||||||||||||||||||||||||||||
this.color = color; | ||||||||||||||||||||||||||||||
this.number = number; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
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
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. It's better to provide already prepared String where is needed 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. Let's fix the comment) |
||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public Color getColor() { | ||||||||||||||||||||||||||||||
return color; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
public void setColor(Color 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.name() | ||||||||||||||||||||||||||||||
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
|
||||||||||||||||||||||||||||||
+ ", number=" + number | ||||||||||||||||||||||||||||||
+ '}'; | ||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package mate.academy.model; | ||
|
||
public enum Color { | ||
RED, | ||
GREEN, | ||
YELLOW, | ||
BLUE, | ||
WHITE, | ||
BLACK, | ||
ORANGE | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,11 @@ | ||||||
package mate.academy.supplier; | ||||||
|
||||||
import java.util.Random; | ||||||
import mate.academy.model.Color; | ||||||
|
||||||
public class ColorSupplier { | ||||||
public Color 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.
Suggested change
|
||||||
int index = new Random().nextInt(Color.values().length); | ||||||
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 class-level variable |
||||||
return Color.values()[index]; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
package mate.academy.supplier; | ||||||
|
||||||
import java.util.Random; | ||||||
import mate.academy.model.Ball; | ||||||
import mate.academy.model.Color; | ||||||
|
||||||
public class Lottery { | ||||||
private static final int MAX_NUMBER = 100; | ||||||
|
||||||
public Ball getRandomBall() { | ||||||
Color color = new 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. ColorSupplier and Random shoud be class-level variables 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
|
||||||
int number = new Random().nextInt(MAX_NUMBER); | ||||||
return new Ball(color, number); | ||||||
} | ||||||
} |
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.
remove comment