-
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
Homework #1247
base: master
Are you sure you want to change the base?
Homework #1247
Conversation
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.
Before you create PR with your homework, you need to go through the checklist under the task and correct all the points described there. The mentor will not check the work until the checklist points are corrected
@@ -3,5 +3,9 @@ | |||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery lottery = new Lottery(); | |||
for (int i = 0; i < 3; i++) { | |||
System.out.println(lottery.getRandomBall().toString()); |
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.
System.out.println(lottery.getRandomBall().toString()); | |
System.out.println(lottery.getRandomBall()); |
public String getRandomColor() { | ||
return null; | ||
public Colors getRandomColor() { | ||
int index = new Random().nextInt(Colors.values().length); |
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.
@@ -0,0 +1,11 @@ | |||
package core.basesyntax; | |||
|
|||
public enum Colors { |
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.
public enum Colors { | |
public enum Color { |
public Ball getRandomBall() { | ||
Ball randBall = new Ball(); | ||
randBall.setColor(supplier.getRandomColor()); | ||
randBall.setNumber(new Random().nextInt(100)); |
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.
public Ball getRandomBall() { | ||
Ball randBall = new Ball(); | ||
randBall.setColor(supplier.getRandomColor()); | ||
randBall.setNumber(randNum.nextInt(100)); |
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.
100 is a magic number.
Avoid direct use of magic numbers instead you should always make it constant with self-descriptive name.
randBall.setNumber(randNum.nextInt(100)); | |
randBall.setNumber(randNum.nextInt(100)); |
import java.util.Random; | ||
|
||
public class Lottery { | ||
private static final int maxNumber = 100; |
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.
private static final int maxNumber = 100; | |
private static final int MAX_BALL_NUMBER = 100; |
public class Lottery { | ||
private static final int maxNumber = 100; | ||
private final ColorSupplier supplier = new ColorSupplier(); | ||
private final Random randNum = new Random(100); |
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.
private final Random randNum = new Random(100); | |
private final Random random = new Random(); |
public class Lottery { | ||
private static final int MAX_BALL_NUMBER = 100; | ||
private final ColorSupplier supplier = new ColorSupplier(); | ||
private final Random random = new Random(100); |
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.
you sent magic number, why if you have constant already?
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; | ||
} |
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.
Better use constructor and you don`t to need getters an setters
package core.basesyntax; | ||
|
||
public class Ball { | ||
private Color color; |
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.
Use String for color
public Color getRandomColor() { | ||
int index = random.nextInt(Color.values().length); | ||
return Color.values()[index]; |
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.
return here String
No description provided.