-
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
Homework #1316
base: master
Are you sure you want to change the base?
Homework #1316
Conversation
…iers for creating new figures
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
@@ -0,0 +1,5 @@ | |||
package core.basesyntax; | |||
|
|||
public interface Area { |
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 Area { | |
public interface AreaCalculator { |
import java.util.Random; | ||
|
||
public class ColorSupplier { | ||
private static final String[] COLORS = {"red", "green", "blue", "yellow", "purple", "orange"}; |
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 public enum Color
@@ -0,0 +1,5 @@ | |||
package core.basesyntax; | |||
|
|||
public interface Drawer { |
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 Drawer { | |
public interface Drawable { |
private static final Random random = new Random(); | ||
|
||
public Figure getRandomFigure() { | ||
int choice = 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.
public enum Color { | ||
RED, GREEN, BLUE, YELLOW, PURPLE, ORANGE, WHITE; | ||
|
||
public static Color 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.
move this method to the ColorSupplier class
and dont use static
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Color.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.
move 10 and white to the class constant
private static final Random random = new Random(); | ||
|
||
public Figure getRandomFigure() { | ||
final int n = 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.
move 5 to the class constant, like FIGURES_COUNT
} | ||
|
||
public Figure getDefaultFigure() { | ||
return new Circle(Color.WHITE, DEFAULT_RADIUS); |
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 enum value a DEFAULT_COLOR constant
return new RightTriangle(color, random.nextDouble() * 10 + 1, | ||
random.nextDouble() * 10 + 1); |
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.
extract random.nextDouble() * 10 + 1 to a private method, make 10 a constant
import java.util.Random; | ||
|
||
public class FigureSupplier { | ||
private static final Random random = new Random(); |
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 Random random = new Random(); | |
private final Random random = new Random(); |
should be same as color supplier
for (int i = 0; i < 3; i++) { | ||
figures[i] = figureSupplier.getRandomFigure(); | ||
} | ||
|
||
for (int i = 3; i < 6; i++) { | ||
figures[i] = figureSupplier.getDefaultFigure(); | ||
} | ||
|
||
for (Figure figure : figures) { | ||
figure.draw(); | ||
} |
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.
can be done in one loop. use length/2
|
||
public class Main { | ||
public static void main(String[] args) { | ||
final int N = 6; |
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 it a class constant with a more meaningful 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.
Great job, with a minor comment
private final ColorSupplier colorSupplier = new ColorSupplier(); | ||
private final Random random = new Random(); | ||
|
||
private double getRandomSide() { |
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 private methods should be below public methods
made abstract figure class and 5 figures, added color and figure supliers for creating new figures