-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
created classes, interface and abstract class for them, class ColorSupplier with public String getRandomColor(), class FigureSupplier with public Figure getRandomFigure() and getDefaultFigure(), also created main with random and default figures #1314
base: master
Are you sure you want to change the base?
Conversation
…pplier with public String getRandomColor(), class FigureSupplier with public Figure getRandomFigure() and getDefaultFigure(), also created main with random and default figures
|
||
public class ColorSupplier { | ||
private final Random random = new Random(); | ||
private final String[] colors = new String[]{"Blue", "Red", "Yellow", "Green", "Black"}; |
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.
create Enum Color
instead of String
private final String[] colors = new String[]{"Blue", "Red", "Yellow", "Green", "Black"}; |
@@ -0,0 +1,13 @@ | |||
package core.basesyntax; | |||
|
|||
public abstract class Figure implements FigureBehaviour { |
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 interface FigureBehaviour { | ||
void printfInfoAboutFigure(); |
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 interface FigureBehaviour { | |
void printfInfoAboutFigure(); | |
public interface Drawable { | |
void draw(); | |
|
||
public Figure getRandomFigure() { | ||
String figureColor = colorSupplier.getRandomColor(); | ||
int randomFigure = random.nextInt(5); |
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 constants instead of numbers
|
||
switch (randomFigure) { | ||
case 0: | ||
return new Circle(figureColor, random.nextDouble() * 9.0 + 1.0); |
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.
All magic numbers, strings, and symbols in your code should be constants.
this article
case 4: | ||
return new Square(figureColor, random.nextDouble() * 9.0 + 1.0); | ||
default: | ||
return null; |
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 null; | |
return getDefaultFigure(); | |
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle("White", 10); |
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.
All magic numbers, strings, and symbols in your code should be constants.
this article
|
||
Figure[] figures = new Figure[6]; | ||
|
||
for (int i = 0; i < 3; i++) { |
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 one loop for
…me of 2 interfaces, used constants instead of numbers and Strings, used one loop for in Main
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.
left a few comments
package core.basesyntax; | ||
|
||
public enum Color { | ||
Blue, |
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.
naming convention: https://mate-academy.github.io/style-guides/java/java.html#s4.8.1-enum-classes
Blue, | |
BLUE, |
private final Color[] colors = new Color[]{Color.Blue, Color.Red, | ||
Color.Yellow, Color.Green, Color.Black}; |
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 Color[] colors = new Color[]{Color.Blue, Color.Red, | |
Color.Yellow, Color.Green, Color.Black}; | |
private final Color[] colors = Color.values(); | |
static final double FIGURE_RADIUS = 9.0 + 1.0; | ||
static final String DEFAULT_CIRCLE_COLOUR = "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.
use Enum
static final double FIGURE_RADIUS = 9.0 + 1.0; | |
static final String DEFAULT_CIRCLE_COLOUR = "White"; | |
static final double FIGURE_RADIUS = 9.0 + 1.0; | |
static final String DEFAULT_COLOR = Color.WHITE.name(); |
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.
Nice
No description provided.