Skip to content
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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

forzen123212
Copy link

No description provided.

public static void main(String[] args) {
FigureSupplier figureSupplier = new FigureSupplier();
GeometricFigure[] figures = new GeometricFigure[FIGURE_COUNT];
for (int i = 0; i < figures.length; i++) {

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

Comment on lines 3 to 5
public enum Color {
BLACK, WHITE, YELLOW, GREEN, BLUE, ORANGE, PURPLE, PINK
}

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

Comment on lines 9 to 10
int index = random.nextInt(Color.values().length);
Color color = Color.values()[index];

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();

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

Comment on lines 6 to 8
public GeometricFigure(String colour) {
this.color = colour;
}

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);

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 {

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

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

Comment on lines 19 to 31
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);
}

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

Copy link

@d1sam d1sam left a 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;
}

Copy link

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();
Copy link

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.

Copy link

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.

Comment on lines 38 to 41
if (random.nextInt(MAX_LENGTH) == 0) {
return random.nextInt(MAX_LENGTH);
}
return random.nextInt(MAX_LENGTH);
Copy link

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);
Copy link

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.

@forzen123212 forzen123212 requested a review from d1sam October 2, 2023 07:51
Copy link

@bhdnchui bhdnchui left a 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");
Copy link

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.

Comment on lines +28 to +29
+ "and path to project and project name should not contain spaces "
+ "or words in cyrillic");
Copy link

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;
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants