-
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
Realization of full application #1280
base: master
Are you sure you want to change the base?
Conversation
# Conflicts: # src/main/java/core/basesyntax/FigureSupplier.java
public static void main(String[] args) { | ||
FigureSupplier figureSupplier = new FigureSupplier(); | ||
GeometricFigure[] figures = new GeometricFigure[FIGURE_COUNT]; | ||
for (int i = 0; i < figures.length; 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.
Minor: Since you already have FIGURE_COUNT to represent the length of an array, I suggest using that variable in for expression for better readability
public enum Color { | ||
BLACK, WHITE, YELLOW, GREEN, BLUE, ORANGE, PURPLE, PINK | ||
} |
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.
It's better practice to put each value on a new line
int index = random.nextInt(Color.values().length); | ||
Color color = 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.
I suggest extracting Color.values() on a class level for further reuse of that variable
import java.util.Random; | ||
|
||
public class FigureSupplier { | ||
private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); |
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.
Each FigureSupplier should have its own ColorSupplier, it should not be a constant
public GeometricFigure(String colour) { | ||
this.color = colour; | ||
} |
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.
minor: please rename colour -> color
private static final int MAX_LENGTH = 100; | ||
private static final int FIGURE_COUNT = 5; | ||
private static final int DEFAULT_RADIUS = 10; | ||
private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); |
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.
Minor: as the task says the default color should be white
@@ -0,0 +1,17 @@ | |||
package core.basesyntax; | |||
|
|||
public abstract class GeometricFigure implements Drawable, AreaCalculator { |
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 pay attention to the task requirements which ask you to create a Figure class, not GeometricFigure
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.
I guess you're not supposed to change this file
switch (index) { | ||
case 0: | ||
return new Circle(randomProperty, randomColor); | ||
case 1: | ||
return new IsoscelesTrapezoid(randomProperty, randomProperty, | ||
randomProperty, randomColor); | ||
case 2: | ||
return new Rectangle(randomProperty, randomProperty, randomColor); | ||
case 3: | ||
return new RightTriangle(randomProperty, randomProperty, randomColor); | ||
default: | ||
return new Square(randomProperty, randomColor); | ||
} |
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.
It seems not quite the right implementation. For example, you will always pass 2 equal numbers to the Rectangle constructor, so you'll always get a Square actually. Similar problems occur for other 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.
Good job, but some changes should be done.
public String getColor() { | ||
return 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.
Please don't add this empty redundant line.
|
||
public class ColorSupplier { | ||
private final Random random = new Random(); | ||
private final Color[] colorSet = Color.values(); |
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 choose better name for this variable, because, it's not a Set, it's an array :) You will learn about Set
in the nearest future.
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 don't make changes inside test package.
if (random.nextInt(MAX_LENGTH) == 0) { | ||
return random.nextInt(MAX_LENGTH); | ||
} | ||
return random.nextInt(MAX_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.
Please simplify this.
The best solution is to just always add 1 and request random numbers from a smaller range:
rand.random(MAX_LENGTH - 1) + 1;
private static final int MAX_LENGTH = 100; | ||
private static final int FIGURE_COUNT = 5; | ||
private static final int DEFAULT_RADIUS = 10; | ||
private static final String DEFAULT_COLOR = String.valueOf(Color.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 name() for getting String representation of enum constants
Don’t use toString() or String.valueOf()(it will call toString() under the hood) for getting String representation of enum constants. toString() is common for all enum constants. If you override this method like below:
@Override
public String() toString() {
return "default";
}
then for every constant toString() will be returning default, that’s not ok. So it’s better to use standard method of enum name() that will be returning always String representation of concrete enum 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, just pay attention to my comments.
@@ -16,7 +16,7 @@ | |||
|
|||
public class StructureTest { | |||
private static final List<String> figureClassNames = List | |||
.of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); | |||
.of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); |
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.
I think you should only provide a solution and not change tests.
+ "and path to project and project name should not contain spaces " | ||
+ "or words in cyrillic"); |
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.
I think you should only provide a solution and not change tests.
@@ -152,4 +152,4 @@ private static List<Class> findClasses(File directory, String packageName) | |||
} | |||
return classes; | |||
} | |||
} | |||
} |
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 same as above.
No description provided.