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

created classes, interface and abstract class for them, class ColorSupplier with public String getRandomColor(), class FigureSupplier with public Figure getRandomFigure() and getDefaultFigure(), also created main with random and default figures #1314

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

Conversation

ddryzhov
Copy link

@ddryzhov ddryzhov commented Oct 7, 2023

No description provided.

…pplier with public String getRandomColor(), class FigureSupplier with public Figure getRandomFigure() and getDefaultFigure(), also created main with random and default figures

public class ColorSupplier {
private final Random random = new Random();
private final String[] colors = new String[]{"Blue", "Red", "Yellow", "Green", "Black"};

Choose a reason for hiding this comment

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

create Enum Color instead of String

Suggested change
private final String[] colors = new String[]{"Blue", "Red", "Yellow", "Green", "Black"};

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

public abstract class Figure implements FigureBehaviour {

Choose a reason for hiding this comment

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

You missed one behavior:
image

Suggested change
public abstract class Figure implements FigureBehaviour {
public abstract class Figure implements AreaCalculator, Drawable {
public interface AreaCalculator {
    double getArea();
}

Comment on lines 3 to 4
public interface FigureBehaviour {
void printfInfoAboutFigure();

Choose a reason for hiding this comment

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

Suggested change
public interface FigureBehaviour {
void printfInfoAboutFigure();
public interface Drawable {
void draw();


public Figure getRandomFigure() {
String figureColor = colorSupplier.getRandomColor();
int randomFigure = random.nextInt(5);

Choose a reason for hiding this comment

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

use constants instead of numbers


switch (randomFigure) {
case 0:
return new Circle(figureColor, random.nextDouble() * 9.0 + 1.0);

Choose a reason for hiding this comment

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

All magic numbers, strings, and symbols in your code should be constants.
this article

case 4:
return new Square(figureColor, random.nextDouble() * 9.0 + 1.0);
default:
return null;

Choose a reason for hiding this comment

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

Suggested change
return null;
return getDefaultFigure();

}

public Figure getDefaultFigure() {
return new Circle("White", 10);

Choose a reason for hiding this comment

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

All magic numbers, strings, and symbols in your code should be constants.
this article


Figure[] figures = new Figure[6];

for (int i = 0; i < 3; i++) {

Choose a reason for hiding this comment

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

use one loop for

…me of 2 interfaces, used constants instead of numbers and Strings, used one loop for in Main
Copy link

@Ivan95kos Ivan95kos left a comment

Choose a reason for hiding this comment

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

left a few comments

package core.basesyntax;

public enum Color {
Blue,

Choose a reason for hiding this comment

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

Comment on lines 7 to 8
private final Color[] colors = new Color[]{Color.Blue, Color.Red,
Color.Yellow, Color.Green, Color.Black};

Choose a reason for hiding this comment

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

Suggested change
private final Color[] colors = new Color[]{Color.Blue, Color.Red,
Color.Yellow, Color.Green, Color.Black};
private final Color[] colors = Color.values();

Comment on lines 7 to 8
static final double FIGURE_RADIUS = 9.0 + 1.0;
static final String DEFAULT_CIRCLE_COLOUR = "White";

Choose a reason for hiding this comment

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

use Enum

Suggested change
static final double FIGURE_RADIUS = 9.0 + 1.0;
static final String DEFAULT_CIRCLE_COLOUR = "White";
static final double FIGURE_RADIUS = 9.0 + 1.0;
static final String DEFAULT_COLOR = Color.WHITE.name();

Copy link

@Ivan95kos Ivan95kos left a comment

Choose a reason for hiding this comment

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

Nice

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.

2 participants