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

implemented all the methods from the task #1284

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

Conversation

YevheniiVlasenko
Copy link

I'm not sure if it could be solved without interface implementation on the Figure class. But in this case, it comes to overridden methods from the interface in the Top Class, and it looks like the interface becomes useless because of method inheritance. Kinda closed circle.

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!
Please, pay attention to my comments.

@@ -0,0 +1,23 @@
package core.basesyntax;

public class Figure implements Drawable, AreaCalculator {
Copy link

Choose a reason for hiding this comment

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

I think we can make this class abstract.

Comment on lines 14 to 22
@Override
public void draw() {

}

@Override
public double getArea() {
return 0;
}
Copy link

Choose a reason for hiding this comment

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

If we make class abstract we will be able to remove that emty overriding.

Comment on lines 6 to 8
public Circle() {

}
Copy link

Choose a reason for hiding this comment

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

I think we should reject creating empty Circle. Let's remove that default constructor.

package core.basesyntax;

public class Figure implements Drawable, AreaCalculator {
private Color color;
Copy link

Choose a reason for hiding this comment

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

Add a constructor public Figure(String color)


public Circle(int radius, Color color) {
this.radius = radius;
this.setColor(color);
Copy link

Choose a reason for hiding this comment

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

Replace it with super(color);.

default:
return new Figure();
}

Copy link

Choose a reason for hiding this comment

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

Empty redundant line.

}

public Figure getDefaultFigure() {
return new Circle(10, Color.WHITE);
Copy link

Choose a reason for hiding this comment

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

Looks like a magic number.


public class Main {
public static void main(String[] args) {
Drawable[] figures = new Drawable[10];
Copy link

Choose a reason for hiding this comment

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

Looks like a magic number.

Color randomColor = colorSupplier.getRandomColor();
int figureIndex = random.nextInt(MAX_FIGURES_TYPES) + 1;
int sideA = random.nextInt(SIZE_LIMIT) + 1;
switch (figureIndex) {
Copy link

Choose a reason for hiding this comment

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

You can simplify it with switch (random.nextInt(MAX_FIGURES_TYPES) + 1).

Comment on lines 27 to 29
int trapezoidSideB = random.nextInt(SIZE_LIMIT) + 1;
int trapezoidHeight = random.nextInt(SIZE_LIMIT) + 1;
return new IsoscelesTrapezoid(sideA, trapezoidSideB, trapezoidHeight, randomColor);
Copy link

Choose a reason for hiding this comment

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

You can extract random.nextInt(SIZE_LIMIT) + 1 to a separate method. And then you will be able to

 return new IsoscelesTrapezoid(getRandomValue(),
      getRandomValue(), 
      getRandomValue(), 
      colorSupplier.getRandomColor()
 );

Comment on lines +18 to +20
for (Drawable figure : figures) {
figure.draw();
}

Choose a reason for hiding this comment

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

You can draw a figure right after you've created it, eliminating the need to iterate over all the figures

}

public Figure getDefaultFigure() {
return new Circle(DEFAULT_CIRCLE_RADIUS, Color.WHITE);

Choose a reason for hiding this comment

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

Minor: it's better to make Color.WHITE as a constant too with a proper name to give some context as you did with radius

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.

3 participants