-
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
doneHomework #1248
base: master
Are you sure you want to change the base?
doneHomework #1248
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
Lottery lottery1 = new Lottery(); | ||
Lottery lottery2 = new Lottery(); | ||
Lottery lottery3 = new Lottery(); |
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.
Do we need 3 markets to buy 3 milk bottles?
System.out.println(lottery1.getRandomBall()); | ||
System.out.println(lottery2.getRandomBall()); | ||
System.out.println(lottery3.getRandomBall()); |
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 for loop for creating several objects of the same class
public class Ball { | ||
|
||
private String 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.
@@ -2,6 +2,9 @@ | |||
|
|||
public class Application { | |||
public static void main(String[] args) { | |||
// create three balls using class Lottery and print information about them in console | |||
Lottery[] lotteries = {new Lottery(), new Lottery(), new Lottery()}; |
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 need only one lottery here
Lottery[] lotteries = {new Lottery(), new Lottery(), new Lottery()}; | |
Lottery lottery = ...; |
public class ColorSupplier { | ||
public String getRandomColor() { | ||
return null; | ||
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.
make random the class level var
@@ -0,0 +1,12 @@ | |||
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.
dont use plural form for enums
public enum Colors { | |
public enum Color { |
int randomNumber = new Random().nextInt(100); | ||
return new Ball(new ColorSupplier().getRandomColor(), randomNumber); |
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 random
, colorSupplier
the class level vars
|
||
public class Lottery { | ||
public Ball getRandomBall() { | ||
int randomNumber = 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.
100 is a maggic number,
consider making it constant
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.
Good job
public static int getMaxNumber() { | ||
return MAX_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.
public static int getMaxNumber() { | |
return MAX_NUMBER; | |
} |
package core.basesyntax; | ||
|
||
public class Ball { | ||
private static final int MAX_NUMBER = 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.
move this to class Lottery
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.
are you suggesting to delete get method for constant?
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.
and move this constant to lottery and to not add get method for it?
public static int getMaxNumber() { | ||
return MAX_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.
You don`t need this method, just use constant
int maxNumber = Lottery.MAX_NUMBER; | ||
int randomNumber = random.nextInt(maxNumber); |
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.
int maxNumber = Lottery.MAX_NUMBER; | |
int randomNumber = random.nextInt(maxNumber); | |
int randomNumber = random.nextInt(MAX_NUMBER); |
No description provided.