-
Notifications
You must be signed in to change notification settings - Fork 1.5k
lottety-hw-01 #1575
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
base: master
Are you sure you want to change the base?
lottety-hw-01 #1575
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 |
---|---|---|
|
@@ -2,6 +2,13 @@ | |
|
||
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(); | ||
Ball ball1 = lottery.getRandomBall(); | ||
Ball ball2 = lottery.getRandomBall(); | ||
Ball ball3 = lottery.getRandomBall(); | ||
|
||
System.out.println(ball1); | ||
System.out.println(ball2); | ||
System.out.println(ball3); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,27 @@ | ||||||
package core.basesyntax; | ||||||
|
||||||
public class Ball { | ||||||
private Color color; | ||||||
|
private Color color; | |
private String color; |
Outdated
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(Color color, int number) { | |
public Ball(String color, int number) { |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,5 @@ | ||||||||||||||||||
package core.basesyntax; | ||||||||||||||||||
|
||||||||||||||||||
public enum Color { | ||||||||||||||||||
RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, WHITE | ||||||||||||||||||
|
RED, GREEN, BLUE, YELLOW, ORANGE, BLACK, WHITE | |
RED, | |
GREEN, | |
BLUE, | |
YELLOW, | |
ORANGE, | |
BLACK, | |
WHITE |
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.
not fixed
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 Color getRandomColor() { | ||||||
|
public Color getRandomColor() { | |
public String getRandomColor() { |
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.
not fixed
Outdated
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.
Creating a new instance of 'Random' each time the method is called can be inefficient if the method is called multiple times. Consider making 'random' a class-level instance variable.
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.
fix comment
Outdated
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 can create it as class-level variable
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||||
package core.basesyntax; | ||||||||
|
||||||||
import java.util.Random; | ||||||||
|
||||||||
class Lottery { | ||||||||
|
class Lottery { | |
public class Lottery { |
Outdated
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.
The instance of Random could be a class-level field instead of being created every time the 'getRandomBall' method is called. This would be more efficient as it avoids unnecessary object creation.
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.
fix comment
Outdated
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.
Creating a new instance of ColorSupplier every time may be inefficient if the getRandomColor method does not depend on instance state. Consider making ColorSupplier a class-level field or its method static if there's no state.
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.
fix comment
Outdated
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.
Magic numbers should be avoided and replaced with named constants for better code readability. Consider creating a constant for the number 101, giving it a meaningful name that explains what it represents.
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.
fix comment
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.
not fixed
Outdated
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 new Ball(color, number); | |
String randomColor = colorSupplier.getRandomColor(); | |
return new Ball(randomColor, 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.
Please use for loop.
if you have 100 balls, you won't need to create 100 lines of code