From ea8e7b544ab388493cbb66ba118831c51cf52ee5 Mon Sep 17 00:00:00 2001 From: mikke966 <130836270+mikke966@users.noreply.github.com> Date: Sat, 14 Oct 2023 18:57:10 +0200 Subject: [PATCH] added solution --- .../java/core/basesyntax/FigureSupplier.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index 1bddb3043a..e2c7b6d01f 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -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;