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

jv-oop-advanced homework #1297

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

Conversation

Zakhar27
Copy link

@Zakhar27 Zakhar27 commented Oct 1, 2023

No description provided.

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 there are some changes should be done.
Also please check this article. It's better to use this method inside print, instead String concatenation.

}
}
for (Figure figure : figures) {
figure.getArea();
Copy link

Choose a reason for hiding this comment

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

Why did you make this call and then ignore result of it?

Copy link
Author

Choose a reason for hiding this comment

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

get.Area is already implemented in a print method so it has no sense to call it 2 times, don't know why I did it)


@Override
public double getArea() {
return (side * height) / 2;
Copy link

Choose a reason for hiding this comment

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

integer division in floating-point context .
Please pay attention to this article.

Copy link
Author

Choose a reason for hiding this comment

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

Should I give height field a double value by default or should I cast it to double in a getArea method? Hope I changed it in a right way


@Override
public double getArea() {
return ((side + side) / 2) * height;
Copy link

Choose a reason for hiding this comment

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

integer division in floating-point context .
Please pay attention to this article.

}

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

Choose a reason for hiding this comment

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

All magic numbers in your code should be constants.
Please see this article to learn about constant fields and their naming requirements.

Copy link
Author

Choose a reason for hiding this comment

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

Didn't notice that, changed

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 minor updates are required.

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

public interface GetArea {
Copy link

Choose a reason for hiding this comment

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

Think about this.

package core.basesyntax;

public interface Print {
void print();
Copy link

Choose a reason for hiding this comment

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

I think figure should draw instead of print. In the task: To 'draw' means to print.
Lets rename it to Drawable with void draw().

Comment on lines 9 to 10
int index = random.nextInt(Color.values().length);
return Color.values()[index];
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 can make Color.values() as separate class field.

Comment on lines 16 to 17
double sideD = side;
double heightD = height;
Copy link

Choose a reason for hiding this comment

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

Remove it.

package core.basesyntax;

public class Circle extends Figure {
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.

You already have Color color field in Figure class.

Copy link
Author

Choose a reason for hiding this comment

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

It has no sence, cuz it has to be inharited from Figure. Changed that everywhere

Comment on lines 15 to 16
double sideD = side;
double heightD = height;
Copy link

Choose a reason for hiding this comment

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

Remove it.

private Random random = new Random();

public Color getRandomColor() {
int index = random.nextInt(Color.values().length);

Choose a reason for hiding this comment

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

Minor: you already have the field which holds colors, you can reuse it here

Comment on lines 6 to 9
static final int FIGURE_AMOUNT = 5;
static final int FIGURE_PARAMETERS_MAX = 20;
static final Color DEFAULT_COLOR = Color.WHITE;
static final int DEFAULT_RADIUS = 10;

Choose a reason for hiding this comment

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

Don't forget to make these fields private

Comment on lines 17 to 33
case 0: {
return new Circle(colorSupplier.getRandomColor(), randomFigureParameter);
}
case 1: {
return new Square(colorSupplier.getRandomColor(), randomFigureParameter);
}
case 2: {
return new Rectangle(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);
}
case 3: {
return new RightTriangle(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);
}
default: {
return new IsoscelesTrapezoid(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);

Choose a reason for hiding this comment

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

since each figure needs a color you can extract colorSupplier.getRandomColor() to a separate variable and reuse

Comment on lines 17 to 33
case 0: {
return new Circle(colorSupplier.getRandomColor(), randomFigureParameter);
}
case 1: {
return new Square(colorSupplier.getRandomColor(), randomFigureParameter);
}
case 2: {
return new Rectangle(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);
}
case 3: {
return new RightTriangle(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);
}
default: {
return new IsoscelesTrapezoid(colorSupplier.getRandomColor(),
randomFigureParameter, randomFigureParameter);

Choose a reason for hiding this comment

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

Your method is not fully random. For example, your Rectangle will always be a square since you pass the same randomFigureParameter there. So sizes of rectangle will always be equal. Please refactor this part

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.

Well done :)

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