Skip to content

Commit

Permalink
added solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke966 committed Oct 14, 2023
1 parent 785de8f commit ea8e7b5
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/main/java/core/basesyntax/FigureSupplier.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
package core.basesyntax;

import java.awt.Color;
import java.util.Random;

public class FigureSupplier {
private static final int RANGE = 101;
private final Random random = new Random();
private static final ColorSupplier colorSupplier = new ColorSupplier();

private final Random random = new Random();

public Figure getRandomFigure() {
Type[] types = Type.values();
Type figure = types[random.nextInt(types.length)];
String randomColor = colorSupplier.getRandomColor();
switch (figure) {
case SQUARE: {
return new Square(random.nextInt(RANGE),
randomColor);
return new Square(random.nextInt(RANGE), randomColor);
}
case ISOSCELESTRAPEZOID: {
return new IsoscelesTrapezoid(random.nextInt(RANGE),
random.nextInt(RANGE), random.nextInt(RANGE),
randomColor);
random.nextInt(RANGE), random.nextInt(RANGE), randomColor);
}
case CIRCLE: {
return new Circle(random.nextInt(RANGE),
colorSupplier.getRandomColor().toString().toLowerCase());
}
case RESTANGLE: {
return new Rectangle(random.nextInt(RANGE), random.nextInt(RANGE),
randomColor);
return new Rectangle(random.nextInt(RANGE), random.nextInt(RANGE), randomColor);
}
case RIGHTTRIANGLE: {
return new RightTriangle(random.nextInt(RANGE),
random.nextInt(RANGE),
randomColor);
return new RightTriangle(random.nextInt(RANGE), random.nextInt(RANGE), randomColor);
}

default: {
throw new IllegalStateException("Unexpected Type value: " + figure);
}
}
}

public Figure getDefaultFigure() {
Circle circle = new Circle(random.nextInt(), colorSupplier.getRandomColor());
return circle;
Expand Down

0 comments on commit ea8e7b5

Please sign in to comment.