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-solution to check #1322

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

Conversation

EugeneKorniuk
Copy link

No description provided.

…which implements two interfaces; add classes for different figures which extends Figure class; override constructors and methods from parent class; add ColorSupplier class & FigureSupplier class to generate figures; create an array of figures in main generate it.
…which implements two interfaces; add classes for different figures which extends Figure class; override constructors and methods from parent class; add ColorSupplier class & FigureSupplier class to generate figures; create an array of figures in main generate it.
Copy link

@andrii-hoienko andrii-hoienko 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 improvements required

random.nextInt(20), random.nextInt(20), random.nextInt(20));
break;
default:
return null;

Choose a reason for hiding this comment

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

I believe in the default case it is better to return defaultFigure instead of null, user does not expect null to be returned in this methid

import java.util.Random;

public class FigureSupplier {
public static final int FIGURE_COUNT = 6;

Choose a reason for hiding this comment

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

If you use this variable in only this class, please make it private

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

Choose a reason for hiding this comment

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

It would be great if you will create packages and put figures in 'figure' package, suppliers to 'supplier'

package core.basesyntax;

public abstract class Figure implements Drawable, AreaCalculator {
private String color;

Choose a reason for hiding this comment

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

It will be better to use enum Color instead of String to represent color

WHITE,
BLACK,
PURPLE

Choose a reason for hiding this comment

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

Dont make unnecessary line breakes


public class ColorSupplier {
public String getRandomColor() {
int index = new 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.

It makes sense to subtract Color.values().length to variable to make code more readable


public class Main {
public static void main(java.lang.String[] args) {
Figure[] figures = new Figure[6];

Choose a reason for hiding this comment

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

Magic number, it makes sense to reuse Figure Supplier#FIGURE_COUNT

for (int i = 0; i < figures.length / 2; i++) {
figures[i] = figureSupplier.getRandomFigure();
}
for (int y = figures.length / 2; y < figures.length; y++) {

Choose a reason for hiding this comment

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

Optional: it is common to use 'i' then 'j' as a variable name in for cycle, but you can you 'i' here as well

Choose a reason for hiding this comment

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

Also to make code more readable it makes sense to create a method something like 'polulateFigures' or 'getFigures' and put the logic of creating and populating array there


@Override
public int areaCalculator() {
return (int)Math.PI * this.radius * this.radius;

Choose a reason for hiding this comment

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

When you cast result of this expression to int value can be lost, so maybe it will be better to make areaCalculator return double

package core.basesyntax;

public interface AreaCalculator {
int areaCalculator();

Choose a reason for hiding this comment

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

Bad method name, 'calculateArea' or something like this will be better

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