From b7ef0908b99939da71e3c92f9d5d019308b881e8 Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 13:58:31 +0300 Subject: [PATCH 01/10] Realization of full application --- README.md | 2 +- .../java/core/basesyntax/Application.java | 18 ++++++++++ .../java/core/basesyntax/AreaCalculator.java | 5 +++ src/main/java/core/basesyntax/Circle.java | 23 ++++++++++++ src/main/java/core/basesyntax/Color.java | 5 +++ .../java/core/basesyntax/ColorSupplier.java | 13 +++++++ src/main/java/core/basesyntax/Drawable.java | 5 +++ .../java/core/basesyntax/FigureSupplier.java | 36 +++++++++++++++++++ .../java/core/basesyntax/GeometricFigure.java | 17 +++++++++ src/main/java/core/basesyntax/HelloWorld.java | 8 ----- .../core/basesyntax/IsoscelesTrapezoid.java | 30 ++++++++++++++++ src/main/java/core/basesyntax/Rectangle.java | 27 ++++++++++++++ .../java/core/basesyntax/RightTriangle.java | 28 +++++++++++++++ src/main/java/core/basesyntax/Square.java | 24 +++++++++++++ src/test/java/core/test/StructureTest.java | 4 +-- 15 files changed, 234 insertions(+), 11 deletions(-) create mode 100644 src/main/java/core/basesyntax/Application.java create mode 100644 src/main/java/core/basesyntax/AreaCalculator.java create mode 100644 src/main/java/core/basesyntax/Circle.java create mode 100644 src/main/java/core/basesyntax/Color.java create mode 100644 src/main/java/core/basesyntax/ColorSupplier.java create mode 100644 src/main/java/core/basesyntax/Drawable.java create mode 100644 src/main/java/core/basesyntax/FigureSupplier.java create mode 100644 src/main/java/core/basesyntax/GeometricFigure.java delete mode 100644 src/main/java/core/basesyntax/HelloWorld.java create mode 100644 src/main/java/core/basesyntax/IsoscelesTrapezoid.java create mode 100644 src/main/java/core/basesyntax/Rectangle.java create mode 100644 src/main/java/core/basesyntax/RightTriangle.java create mode 100644 src/main/java/core/basesyntax/Square.java diff --git a/README.md b/README.md index 00bbde2294..220924ade8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ __Solve the task using OOP principles__ Task: There are some figures of the following types: square, rectangle, right triangle, circle, isosceles trapezoid. -You need to create corresponding classes for them(`Square`, `Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) +You need to create corresponding classes for them(`Square`, `core.basesyntax.Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) All figures have - **state** - all figures have `color`, but each figure type can also have one or several unique properties (`radius` for circle, `firstLeg` and `secondLeg` for right triangle, and so on). diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java new file mode 100644 index 0000000000..af1382bf56 --- /dev/null +++ b/src/main/java/core/basesyntax/Application.java @@ -0,0 +1,18 @@ +package core.basesyntax; + +public class Application { + private static final int FIGURE_COUNT = 6; + + public static void main(String[] args) { + FigureSupplier figureSupplier = new FigureSupplier(); + GeometricFigure[] figures = new GeometricFigure[FIGURE_COUNT]; + for (int i = 0; i < figures.length; i++) { + if (i < FIGURE_COUNT / 2) { + figures[i] = figureSupplier.getRandomFigure(); + } else { + figures[i] = figureSupplier.getDefaultFigure(); + } + figures[i].draw(); + } + } +} diff --git a/src/main/java/core/basesyntax/AreaCalculator.java b/src/main/java/core/basesyntax/AreaCalculator.java new file mode 100644 index 0000000000..673262c690 --- /dev/null +++ b/src/main/java/core/basesyntax/AreaCalculator.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public interface AreaCalculator { + double getArea(); +} diff --git a/src/main/java/core/basesyntax/Circle.java b/src/main/java/core/basesyntax/Circle.java new file mode 100644 index 0000000000..619c245be2 --- /dev/null +++ b/src/main/java/core/basesyntax/Circle.java @@ -0,0 +1,23 @@ +package core.basesyntax; + +public class Circle extends GeometricFigure { + private final int radius; + + public Circle(int radius, String color) { + super(color); + this.radius = radius; + } + + @Override + public double getArea() { + return Math.PI * Math.pow(radius, 2); + } + + @Override + public void draw() { + System.out.println("Figure: circle, area: " + + getArea() + + " , radius: " + + radius + ", color: " + color); + } +} diff --git a/src/main/java/core/basesyntax/Color.java b/src/main/java/core/basesyntax/Color.java new file mode 100644 index 0000000000..ededf14616 --- /dev/null +++ b/src/main/java/core/basesyntax/Color.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public enum Color { + BLACK, WHITE, YELLOW, GREEN, BLUE, ORANGE, PURPLE, PINK +} diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java new file mode 100644 index 0000000000..ed385c9970 --- /dev/null +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -0,0 +1,13 @@ +package core.basesyntax; + +import java.util.Random; + +public class ColorSupplier { + private final Random random = new Random(); + + public String getRandomColor() { + int index = random.nextInt(Color.values().length); + Color color = Color.values()[index]; + return color.name(); + } +} diff --git a/src/main/java/core/basesyntax/Drawable.java b/src/main/java/core/basesyntax/Drawable.java new file mode 100644 index 0000000000..d045270178 --- /dev/null +++ b/src/main/java/core/basesyntax/Drawable.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public interface Drawable { + void draw(); +} diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java new file mode 100644 index 0000000000..b54083af74 --- /dev/null +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -0,0 +1,36 @@ +package core.basesyntax; + +import java.util.Random; + +public class FigureSupplier { + private static final Random RANDOM = new Random(); + private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); + private static final int MAX_LENGTH = 100; + private static final int FIGURE_COUNT = 5; + + private static final int DEFAULT_RADIUS = 10; + private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); + + public GeometricFigure getRandomFigure() { + final String randomColor = COLOR_SUPPLIER.getRandomColor(); + final int index = RANDOM.nextInt(FIGURE_COUNT); + final int randomProperty = RANDOM.nextInt(MAX_LENGTH); + switch (index) { + case 0: + return new Circle(randomProperty, randomColor); + case 1: + return new IsoscelesTrapezoid(randomProperty, randomProperty, + randomProperty, randomColor); + case 2: + return new Rectangle(randomProperty, randomProperty, randomColor); + case 3: + return new RightTriangle(randomProperty, randomProperty, randomColor); + default: + return new Square(randomProperty, randomColor); + } + } + + public GeometricFigure getDefaultFigure() { + return new Circle(DEFAULT_RADIUS, DEFAULT_COLOR); + } +} diff --git a/src/main/java/core/basesyntax/GeometricFigure.java b/src/main/java/core/basesyntax/GeometricFigure.java new file mode 100644 index 0000000000..8c627d59a5 --- /dev/null +++ b/src/main/java/core/basesyntax/GeometricFigure.java @@ -0,0 +1,17 @@ +package core.basesyntax; + +public abstract class GeometricFigure implements Drawable, AreaCalculator { + protected String color; + + public GeometricFigure(String colour) { + this.color = colour; + } + + public String getColour() { + return color; + } + + public void setColour() { + this.color = color; + } +} diff --git a/src/main/java/core/basesyntax/HelloWorld.java b/src/main/java/core/basesyntax/HelloWorld.java deleted file mode 100644 index 97db782bf7..0000000000 --- a/src/main/java/core/basesyntax/HelloWorld.java +++ /dev/null @@ -1,8 +0,0 @@ -package core.basesyntax; - -/** - * Feel free to remove this class and create your own. - */ -public class HelloWorld { - -} diff --git a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java new file mode 100644 index 0000000000..786217e9b9 --- /dev/null +++ b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java @@ -0,0 +1,30 @@ +package core.basesyntax; + +public class IsoscelesTrapezoid extends GeometricFigure { + private final int height; + private final int firstBase; + private final int secondBase; + + public IsoscelesTrapezoid(int height, int firstBase, int secondBase, String color) { + super(color); + this.height = height; + this.firstBase = firstBase; + this.secondBase = secondBase; + } + + @Override + public double getArea() { + return (double) ((firstBase + secondBase) * height) / 2; + } + + @Override + public void draw() { + System.out.println("Figure: isosceles trapezoid, area: " + + getArea() + + " , height: " + height + + ", first Base: " + firstBase + + ", secondBase: " + + secondBase + + ", color: " + color); + } +} diff --git a/src/main/java/core/basesyntax/Rectangle.java b/src/main/java/core/basesyntax/Rectangle.java new file mode 100644 index 0000000000..00e55e1c34 --- /dev/null +++ b/src/main/java/core/basesyntax/Rectangle.java @@ -0,0 +1,27 @@ + +package core.basesyntax; + +public class Rectangle extends GeometricFigure { + private final int firstSide; + private final int secondSide; + + public Rectangle(int firstSide, int secondSide, String color) { + super(color); + this.firstSide = firstSide; + this.secondSide = secondSide; + } + + @Override + public double getArea() { + return firstSide * secondSide; + } + + @Override + public void draw() { + System.out.println("Figure: rectangle, area: " + getArea() + + " , firstSide: " + + firstSide + ", secondSide: " + + secondSide + ", color: " + + color); + } +} diff --git a/src/main/java/core/basesyntax/RightTriangle.java b/src/main/java/core/basesyntax/RightTriangle.java new file mode 100644 index 0000000000..7932deb05e --- /dev/null +++ b/src/main/java/core/basesyntax/RightTriangle.java @@ -0,0 +1,28 @@ +package core.basesyntax; + +public class RightTriangle extends GeometricFigure { + private final int firstLeg; + private final int secondLeg; + + public RightTriangle(int firstLeg, int secondLeg, String color) { + super(color); + this.firstLeg = firstLeg; + this.secondLeg = secondLeg; + } + + @Override + public void draw() { + System.out.println("Figure: right triangle, area: " + + getArea() + + " , first leg: " + + firstLeg + ", second leg:" + + secondLeg + + ", color: " + + color); + } + + @Override + public double getArea() { + return (double) firstLeg * secondLeg / 2; + } +} diff --git a/src/main/java/core/basesyntax/Square.java b/src/main/java/core/basesyntax/Square.java new file mode 100644 index 0000000000..675d117f24 --- /dev/null +++ b/src/main/java/core/basesyntax/Square.java @@ -0,0 +1,24 @@ +package core.basesyntax; + +public class Square extends GeometricFigure { + private final int side; + + public Square(int side, String color) { + super(color); + this.side = side; + } + + @Override + public void draw() { + System.out.println("Figure: square, area: " + + getArea() + + " , side: " + + side + ", color: " + + color); + } + + @Override + public double getArea() { + return side * side; + } +} diff --git a/src/test/java/core/test/StructureTest.java b/src/test/java/core/test/StructureTest.java index 54e70eee5b..59a173c3f3 100644 --- a/src/test/java/core/test/StructureTest.java +++ b/src/test/java/core/test/StructureTest.java @@ -16,14 +16,14 @@ public class StructureTest { private static final List figureClassNames = List - .of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); + .of("Circle", "Square", "IsoscelesTrapezoid", "core.basesyntax.Rectangle", "RightTriangle"); private static List allClasses = new ArrayList<>(); @BeforeClass public static void init() { try { allClasses = getClasses("core.basesyntax"); - if (allClasses.size() == 0) { + if (allClasses.isEmpty()) { Assert.fail("You should not rename base core.basesyntax package " + "and path to project and project name should not contain spaces " + "or words in cyrillic"); From 515b89f03c9a21ade87869743d14cbeefa821f5f Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 13:58:31 +0300 Subject: [PATCH 02/10] Realization of full application --- README.md | 2 +- .../java/core/basesyntax/Application.java | 18 ++++++++++ .../java/core/basesyntax/AreaCalculator.java | 5 +++ src/main/java/core/basesyntax/Circle.java | 23 ++++++++++++ src/main/java/core/basesyntax/Color.java | 5 +++ .../java/core/basesyntax/ColorSupplier.java | 13 +++++++ src/main/java/core/basesyntax/Drawable.java | 5 +++ .../java/core/basesyntax/FigureSupplier.java | 36 +++++++++++++++++++ .../java/core/basesyntax/GeometricFigure.java | 17 +++++++++ src/main/java/core/basesyntax/HelloWorld.java | 8 ----- .../core/basesyntax/IsoscelesTrapezoid.java | 30 ++++++++++++++++ src/main/java/core/basesyntax/Rectangle.java | 27 ++++++++++++++ .../java/core/basesyntax/RightTriangle.java | 28 +++++++++++++++ src/main/java/core/basesyntax/Square.java | 24 +++++++++++++ src/test/java/core/test/StructureTest.java | 2 +- 15 files changed, 233 insertions(+), 10 deletions(-) create mode 100644 src/main/java/core/basesyntax/Application.java create mode 100644 src/main/java/core/basesyntax/AreaCalculator.java create mode 100644 src/main/java/core/basesyntax/Circle.java create mode 100644 src/main/java/core/basesyntax/Color.java create mode 100644 src/main/java/core/basesyntax/ColorSupplier.java create mode 100644 src/main/java/core/basesyntax/Drawable.java create mode 100644 src/main/java/core/basesyntax/FigureSupplier.java create mode 100644 src/main/java/core/basesyntax/GeometricFigure.java delete mode 100644 src/main/java/core/basesyntax/HelloWorld.java create mode 100644 src/main/java/core/basesyntax/IsoscelesTrapezoid.java create mode 100644 src/main/java/core/basesyntax/Rectangle.java create mode 100644 src/main/java/core/basesyntax/RightTriangle.java create mode 100644 src/main/java/core/basesyntax/Square.java diff --git a/README.md b/README.md index 00bbde2294..220924ade8 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ __Solve the task using OOP principles__ Task: There are some figures of the following types: square, rectangle, right triangle, circle, isosceles trapezoid. -You need to create corresponding classes for them(`Square`, `Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) +You need to create corresponding classes for them(`Square`, `core.basesyntax.Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) All figures have - **state** - all figures have `color`, but each figure type can also have one or several unique properties (`radius` for circle, `firstLeg` and `secondLeg` for right triangle, and so on). diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java new file mode 100644 index 0000000000..af1382bf56 --- /dev/null +++ b/src/main/java/core/basesyntax/Application.java @@ -0,0 +1,18 @@ +package core.basesyntax; + +public class Application { + private static final int FIGURE_COUNT = 6; + + public static void main(String[] args) { + FigureSupplier figureSupplier = new FigureSupplier(); + GeometricFigure[] figures = new GeometricFigure[FIGURE_COUNT]; + for (int i = 0; i < figures.length; i++) { + if (i < FIGURE_COUNT / 2) { + figures[i] = figureSupplier.getRandomFigure(); + } else { + figures[i] = figureSupplier.getDefaultFigure(); + } + figures[i].draw(); + } + } +} diff --git a/src/main/java/core/basesyntax/AreaCalculator.java b/src/main/java/core/basesyntax/AreaCalculator.java new file mode 100644 index 0000000000..673262c690 --- /dev/null +++ b/src/main/java/core/basesyntax/AreaCalculator.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public interface AreaCalculator { + double getArea(); +} diff --git a/src/main/java/core/basesyntax/Circle.java b/src/main/java/core/basesyntax/Circle.java new file mode 100644 index 0000000000..619c245be2 --- /dev/null +++ b/src/main/java/core/basesyntax/Circle.java @@ -0,0 +1,23 @@ +package core.basesyntax; + +public class Circle extends GeometricFigure { + private final int radius; + + public Circle(int radius, String color) { + super(color); + this.radius = radius; + } + + @Override + public double getArea() { + return Math.PI * Math.pow(radius, 2); + } + + @Override + public void draw() { + System.out.println("Figure: circle, area: " + + getArea() + + " , radius: " + + radius + ", color: " + color); + } +} diff --git a/src/main/java/core/basesyntax/Color.java b/src/main/java/core/basesyntax/Color.java new file mode 100644 index 0000000000..ededf14616 --- /dev/null +++ b/src/main/java/core/basesyntax/Color.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public enum Color { + BLACK, WHITE, YELLOW, GREEN, BLUE, ORANGE, PURPLE, PINK +} diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java new file mode 100644 index 0000000000..ed385c9970 --- /dev/null +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -0,0 +1,13 @@ +package core.basesyntax; + +import java.util.Random; + +public class ColorSupplier { + private final Random random = new Random(); + + public String getRandomColor() { + int index = random.nextInt(Color.values().length); + Color color = Color.values()[index]; + return color.name(); + } +} diff --git a/src/main/java/core/basesyntax/Drawable.java b/src/main/java/core/basesyntax/Drawable.java new file mode 100644 index 0000000000..d045270178 --- /dev/null +++ b/src/main/java/core/basesyntax/Drawable.java @@ -0,0 +1,5 @@ +package core.basesyntax; + +public interface Drawable { + void draw(); +} diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java new file mode 100644 index 0000000000..0e77f243fa --- /dev/null +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -0,0 +1,36 @@ +package core.basesyntax; + +import java.util.Random; + +public class FigureSupplier { + private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); + private static final int MAX_LENGTH = 100; + private static final int FIGURE_COUNT = 5; + private static final int DEFAULT_RADIUS = 10; + private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); + + private final Random random = new Random(); + + public GeometricFigure getRandomFigure() { + final String randomColor = COLOR_SUPPLIER.getRandomColor(); + final int index = random.nextInt(FIGURE_COUNT); + final int randomProperty = random.nextInt(MAX_LENGTH); + switch (index) { + case 0: + return new Circle(randomProperty, randomColor); + case 1: + return new IsoscelesTrapezoid(randomProperty, randomProperty, + randomProperty, randomColor); + case 2: + return new Rectangle(randomProperty, randomProperty, randomColor); + case 3: + return new RightTriangle(randomProperty, randomProperty, randomColor); + default: + return new Square(randomProperty, randomColor); + } + } + + public GeometricFigure getDefaultFigure() { + return new Circle(DEFAULT_RADIUS, DEFAULT_COLOR); + } +} diff --git a/src/main/java/core/basesyntax/GeometricFigure.java b/src/main/java/core/basesyntax/GeometricFigure.java new file mode 100644 index 0000000000..8c627d59a5 --- /dev/null +++ b/src/main/java/core/basesyntax/GeometricFigure.java @@ -0,0 +1,17 @@ +package core.basesyntax; + +public abstract class GeometricFigure implements Drawable, AreaCalculator { + protected String color; + + public GeometricFigure(String colour) { + this.color = colour; + } + + public String getColour() { + return color; + } + + public void setColour() { + this.color = color; + } +} diff --git a/src/main/java/core/basesyntax/HelloWorld.java b/src/main/java/core/basesyntax/HelloWorld.java deleted file mode 100644 index 97db782bf7..0000000000 --- a/src/main/java/core/basesyntax/HelloWorld.java +++ /dev/null @@ -1,8 +0,0 @@ -package core.basesyntax; - -/** - * Feel free to remove this class and create your own. - */ -public class HelloWorld { - -} diff --git a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java new file mode 100644 index 0000000000..786217e9b9 --- /dev/null +++ b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java @@ -0,0 +1,30 @@ +package core.basesyntax; + +public class IsoscelesTrapezoid extends GeometricFigure { + private final int height; + private final int firstBase; + private final int secondBase; + + public IsoscelesTrapezoid(int height, int firstBase, int secondBase, String color) { + super(color); + this.height = height; + this.firstBase = firstBase; + this.secondBase = secondBase; + } + + @Override + public double getArea() { + return (double) ((firstBase + secondBase) * height) / 2; + } + + @Override + public void draw() { + System.out.println("Figure: isosceles trapezoid, area: " + + getArea() + + " , height: " + height + + ", first Base: " + firstBase + + ", secondBase: " + + secondBase + + ", color: " + color); + } +} diff --git a/src/main/java/core/basesyntax/Rectangle.java b/src/main/java/core/basesyntax/Rectangle.java new file mode 100644 index 0000000000..00e55e1c34 --- /dev/null +++ b/src/main/java/core/basesyntax/Rectangle.java @@ -0,0 +1,27 @@ + +package core.basesyntax; + +public class Rectangle extends GeometricFigure { + private final int firstSide; + private final int secondSide; + + public Rectangle(int firstSide, int secondSide, String color) { + super(color); + this.firstSide = firstSide; + this.secondSide = secondSide; + } + + @Override + public double getArea() { + return firstSide * secondSide; + } + + @Override + public void draw() { + System.out.println("Figure: rectangle, area: " + getArea() + + " , firstSide: " + + firstSide + ", secondSide: " + + secondSide + ", color: " + + color); + } +} diff --git a/src/main/java/core/basesyntax/RightTriangle.java b/src/main/java/core/basesyntax/RightTriangle.java new file mode 100644 index 0000000000..7932deb05e --- /dev/null +++ b/src/main/java/core/basesyntax/RightTriangle.java @@ -0,0 +1,28 @@ +package core.basesyntax; + +public class RightTriangle extends GeometricFigure { + private final int firstLeg; + private final int secondLeg; + + public RightTriangle(int firstLeg, int secondLeg, String color) { + super(color); + this.firstLeg = firstLeg; + this.secondLeg = secondLeg; + } + + @Override + public void draw() { + System.out.println("Figure: right triangle, area: " + + getArea() + + " , first leg: " + + firstLeg + ", second leg:" + + secondLeg + + ", color: " + + color); + } + + @Override + public double getArea() { + return (double) firstLeg * secondLeg / 2; + } +} diff --git a/src/main/java/core/basesyntax/Square.java b/src/main/java/core/basesyntax/Square.java new file mode 100644 index 0000000000..675d117f24 --- /dev/null +++ b/src/main/java/core/basesyntax/Square.java @@ -0,0 +1,24 @@ +package core.basesyntax; + +public class Square extends GeometricFigure { + private final int side; + + public Square(int side, String color) { + super(color); + this.side = side; + } + + @Override + public void draw() { + System.out.println("Figure: square, area: " + + getArea() + + " , side: " + + side + ", color: " + + color); + } + + @Override + public double getArea() { + return side * side; + } +} diff --git a/src/test/java/core/test/StructureTest.java b/src/test/java/core/test/StructureTest.java index 54e70eee5b..ebfd8c668f 100644 --- a/src/test/java/core/test/StructureTest.java +++ b/src/test/java/core/test/StructureTest.java @@ -16,7 +16,7 @@ public class StructureTest { private static final List figureClassNames = List - .of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); + .of("Circle", "Square", "IsoscelesTrapezoid", "core.basesyntax.Rectangle", "RightTriangle"); private static List allClasses = new ArrayList<>(); @BeforeClass From 51c56c34fbd90052b5ff57e5c428550b92b5b18b Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 16:48:31 +0300 Subject: [PATCH 03/10] Realization of full application --- src/main/java/core/basesyntax/Rectangle.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/core/basesyntax/Rectangle.java b/src/main/java/core/basesyntax/Rectangle.java index 00e55e1c34..d18202142b 100644 --- a/src/main/java/core/basesyntax/Rectangle.java +++ b/src/main/java/core/basesyntax/Rectangle.java @@ -1,4 +1,3 @@ - package core.basesyntax; public class Rectangle extends GeometricFigure { From 5e19cc3457a3da017ed8a04d9de7c61b0af2bffe Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 16:52:16 +0300 Subject: [PATCH 04/10] Realization of full application --- README.md | 2 +- src/main/java/core/basesyntax/FigureSupplier.java | 14 -------------- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/README.md b/README.md index 220924ade8..00bbde2294 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ __Solve the task using OOP principles__ Task: There are some figures of the following types: square, rectangle, right triangle, circle, isosceles trapezoid. -You need to create corresponding classes for them(`Square`, `core.basesyntax.Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) +You need to create corresponding classes for them(`Square`, `Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) All figures have - **state** - all figures have `color`, but each figure type can also have one or several unique properties (`radius` for circle, `firstLeg` and `secondLeg` for right triangle, and so on). diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index e025cffee0..326155b0f0 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -3,7 +3,6 @@ import java.util.Random; public class FigureSupplier { -<<<<<<< HEAD private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); private static final int MAX_LENGTH = 100; private static final int FIGURE_COUNT = 5; @@ -16,20 +15,7 @@ public GeometricFigure getRandomFigure() { final String randomColor = COLOR_SUPPLIER.getRandomColor(); final int index = random.nextInt(FIGURE_COUNT); final int randomProperty = random.nextInt(MAX_LENGTH); -======= - private static final Random RANDOM = new Random(); - private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); - private static final int MAX_LENGTH = 100; - private static final int FIGURE_COUNT = 5; - - private static final int DEFAULT_RADIUS = 10; - private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); - public GeometricFigure getRandomFigure() { - final String randomColor = COLOR_SUPPLIER.getRandomColor(); - final int index = RANDOM.nextInt(FIGURE_COUNT); - final int randomProperty = RANDOM.nextInt(MAX_LENGTH); ->>>>>>> origin/ForzenBranch switch (index) { case 0: return new Circle(randomProperty, randomColor); From 7fa69f2004c25d5da08a1eea284519a02b70b55e Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 16:52:16 +0300 Subject: [PATCH 05/10] Realization of full application --- README.md | 2 +- src/main/java/core/basesyntax/FigureSupplier.java | 14 -------------- src/test/java/core/test/StructureTest.java | 10 +++++----- 3 files changed, 6 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 220924ade8..00bbde2294 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ __Solve the task using OOP principles__ Task: There are some figures of the following types: square, rectangle, right triangle, circle, isosceles trapezoid. -You need to create corresponding classes for them(`Square`, `core.basesyntax.Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) +You need to create corresponding classes for them(`Square`, `Rectangle`, `RightTriangle`, `Circle`, `IsoscelesTrapezoid`) All figures have - **state** - all figures have `color`, but each figure type can also have one or several unique properties (`radius` for circle, `firstLeg` and `secondLeg` for right triangle, and so on). diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index e025cffee0..326155b0f0 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -3,7 +3,6 @@ import java.util.Random; public class FigureSupplier { -<<<<<<< HEAD private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); private static final int MAX_LENGTH = 100; private static final int FIGURE_COUNT = 5; @@ -16,20 +15,7 @@ public GeometricFigure getRandomFigure() { final String randomColor = COLOR_SUPPLIER.getRandomColor(); final int index = random.nextInt(FIGURE_COUNT); final int randomProperty = random.nextInt(MAX_LENGTH); -======= - private static final Random RANDOM = new Random(); - private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); - private static final int MAX_LENGTH = 100; - private static final int FIGURE_COUNT = 5; - - private static final int DEFAULT_RADIUS = 10; - private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); - public GeometricFigure getRandomFigure() { - final String randomColor = COLOR_SUPPLIER.getRandomColor(); - final int index = RANDOM.nextInt(FIGURE_COUNT); - final int randomProperty = RANDOM.nextInt(MAX_LENGTH); ->>>>>>> origin/ForzenBranch switch (index) { case 0: return new Circle(randomProperty, randomColor); diff --git a/src/test/java/core/test/StructureTest.java b/src/test/java/core/test/StructureTest.java index 59a173c3f3..e6a60d1303 100644 --- a/src/test/java/core/test/StructureTest.java +++ b/src/test/java/core/test/StructureTest.java @@ -16,17 +16,17 @@ public class StructureTest { private static final List figureClassNames = List - .of("Circle", "Square", "IsoscelesTrapezoid", "core.basesyntax.Rectangle", "RightTriangle"); + .of("Circle", "Square", "IsoscelesTrapezoid", "Rectangle", "RightTriangle"); private static List allClasses = new ArrayList<>(); @BeforeClass public static void init() { try { allClasses = getClasses("core.basesyntax"); - if (allClasses.isEmpty()) { + if (allClasses.size() == 0) { Assert.fail("You should not rename base core.basesyntax package " - + "and path to project and project name should not contain spaces " - + "or words in cyrillic"); + + "and path to project and project name should not contain spaces " + + "or words in cyrillic"); } } catch (Exception e) { throw new RuntimeException("Could not load classes ", e); @@ -152,4 +152,4 @@ private static List findClasses(File directory, String packageName) } return classes; } -} +} \ No newline at end of file From cd42fa0505c7f46ea46f61020ef8627126e45cb5 Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Wed, 27 Sep 2023 17:30:21 +0300 Subject: [PATCH 06/10] Realization of full application --- src/main/java/core/basesyntax/Circle.java | 2 +- src/main/java/core/basesyntax/IsoscelesTrapezoid.java | 2 +- src/main/java/core/basesyntax/Rectangle.java | 2 +- src/main/java/core/basesyntax/RightTriangle.java | 2 +- src/main/java/core/basesyntax/Square.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/core/basesyntax/Circle.java b/src/main/java/core/basesyntax/Circle.java index 619c245be2..816fc1853e 100644 --- a/src/main/java/core/basesyntax/Circle.java +++ b/src/main/java/core/basesyntax/Circle.java @@ -17,7 +17,7 @@ public double getArea() { public void draw() { System.out.println("Figure: circle, area: " + getArea() - + " , radius: " + + ", radius: " + radius + ", color: " + color); } } diff --git a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java index 786217e9b9..7ce1343941 100644 --- a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java +++ b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java @@ -21,7 +21,7 @@ public double getArea() { public void draw() { System.out.println("Figure: isosceles trapezoid, area: " + getArea() - + " , height: " + height + + ", height: " + height + ", first Base: " + firstBase + ", secondBase: " + secondBase diff --git a/src/main/java/core/basesyntax/Rectangle.java b/src/main/java/core/basesyntax/Rectangle.java index d18202142b..9feb14e313 100644 --- a/src/main/java/core/basesyntax/Rectangle.java +++ b/src/main/java/core/basesyntax/Rectangle.java @@ -18,7 +18,7 @@ public double getArea() { @Override public void draw() { System.out.println("Figure: rectangle, area: " + getArea() - + " , firstSide: " + + ", firstSide: " + firstSide + ", secondSide: " + secondSide + ", color: " + color); diff --git a/src/main/java/core/basesyntax/RightTriangle.java b/src/main/java/core/basesyntax/RightTriangle.java index 7932deb05e..c70df9ff8c 100644 --- a/src/main/java/core/basesyntax/RightTriangle.java +++ b/src/main/java/core/basesyntax/RightTriangle.java @@ -14,7 +14,7 @@ public RightTriangle(int firstLeg, int secondLeg, String color) { public void draw() { System.out.println("Figure: right triangle, area: " + getArea() - + " , first leg: " + + ", first leg: " + firstLeg + ", second leg:" + secondLeg + ", color: " diff --git a/src/main/java/core/basesyntax/Square.java b/src/main/java/core/basesyntax/Square.java index 675d117f24..a425130f32 100644 --- a/src/main/java/core/basesyntax/Square.java +++ b/src/main/java/core/basesyntax/Square.java @@ -12,7 +12,7 @@ public Square(int side, String color) { public void draw() { System.out.println("Figure: square, area: " + getArea() - + " , side: " + + ", side: " + side + ", color: " + color); } From a50dbd1718da8d8d8cd37470ad8d47e780e07ce4 Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Thu, 28 Sep 2023 18:35:13 +0300 Subject: [PATCH 07/10] Fixed style and main method --- .../java/core/basesyntax/Application.java | 4 +-- src/main/java/core/basesyntax/Circle.java | 2 +- src/main/java/core/basesyntax/Color.java | 9 +++++- .../java/core/basesyntax/ColorSupplier.java | 5 ++-- src/main/java/core/basesyntax/Figure.java | 14 ++++++++++ .../java/core/basesyntax/FigureSupplier.java | 28 +++++++++++-------- .../java/core/basesyntax/GeometricFigure.java | 17 ----------- .../core/basesyntax/IsoscelesTrapezoid.java | 2 +- src/main/java/core/basesyntax/Rectangle.java | 2 +- .../java/core/basesyntax/RightTriangle.java | 2 +- src/main/java/core/basesyntax/Square.java | 2 +- 11 files changed, 47 insertions(+), 40 deletions(-) create mode 100644 src/main/java/core/basesyntax/Figure.java delete mode 100644 src/main/java/core/basesyntax/GeometricFigure.java diff --git a/src/main/java/core/basesyntax/Application.java b/src/main/java/core/basesyntax/Application.java index af1382bf56..1c9957c578 100644 --- a/src/main/java/core/basesyntax/Application.java +++ b/src/main/java/core/basesyntax/Application.java @@ -5,8 +5,8 @@ public class Application { public static void main(String[] args) { FigureSupplier figureSupplier = new FigureSupplier(); - GeometricFigure[] figures = new GeometricFigure[FIGURE_COUNT]; - for (int i = 0; i < figures.length; i++) { + Figure[] figures = new Figure[FIGURE_COUNT]; + for (int i = 0; i < FIGURE_COUNT; i++) { if (i < FIGURE_COUNT / 2) { figures[i] = figureSupplier.getRandomFigure(); } else { diff --git a/src/main/java/core/basesyntax/Circle.java b/src/main/java/core/basesyntax/Circle.java index 816fc1853e..2818c14e8c 100644 --- a/src/main/java/core/basesyntax/Circle.java +++ b/src/main/java/core/basesyntax/Circle.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class Circle extends GeometricFigure { +public class Circle extends Figure { private final int radius; public Circle(int radius, String color) { diff --git a/src/main/java/core/basesyntax/Color.java b/src/main/java/core/basesyntax/Color.java index ededf14616..a2caace53f 100644 --- a/src/main/java/core/basesyntax/Color.java +++ b/src/main/java/core/basesyntax/Color.java @@ -1,5 +1,12 @@ package core.basesyntax; public enum Color { - BLACK, WHITE, YELLOW, GREEN, BLUE, ORANGE, PURPLE, PINK + BLACK, + WHITE, + YELLOW, + GREEN, + BLUE, + ORANGE, + PURPLE, + PINK } diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index ed385c9970..1fd5f96c18 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -7,7 +7,6 @@ public class ColorSupplier { public String getRandomColor() { int index = random.nextInt(Color.values().length); - Color color = Color.values()[index]; - return color.name(); + return Color.values()[index].name(); } -} +} \ No newline at end of file diff --git a/src/main/java/core/basesyntax/Figure.java b/src/main/java/core/basesyntax/Figure.java new file mode 100644 index 0000000000..eca3a05814 --- /dev/null +++ b/src/main/java/core/basesyntax/Figure.java @@ -0,0 +1,14 @@ +package core.basesyntax; + +public abstract class Figure implements Drawable, AreaCalculator { + protected String color; + + public Figure(String color) { + this.color = color; + } + + public String getColor() { + return color; + } + +} diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index 326155b0f0..cdba0a4048 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -3,35 +3,39 @@ import java.util.Random; public class FigureSupplier { - private static final ColorSupplier COLOR_SUPPLIER = new ColorSupplier(); private static final int MAX_LENGTH = 100; private static final int FIGURE_COUNT = 5; private static final int DEFAULT_RADIUS = 10; - private static final String DEFAULT_COLOR = String.valueOf(Color.GREEN); + private static final String DEFAULT_COLOR = String.valueOf(Color.WHITE); private final Random random = new Random(); + private final ColorSupplier supplier = new ColorSupplier(); - public GeometricFigure getRandomFigure() { - final String randomColor = COLOR_SUPPLIER.getRandomColor(); + public Figure getRandomFigure() { + String color = supplier.getRandomColor(); final int index = random.nextInt(FIGURE_COUNT); - final int randomProperty = random.nextInt(MAX_LENGTH); switch (index) { case 0: - return new Circle(randomProperty, randomColor); + return new Circle(getRandomNumber(), color); case 1: - return new IsoscelesTrapezoid(randomProperty, randomProperty, - randomProperty, randomColor); + return new IsoscelesTrapezoid(getRandomNumber(), getRandomNumber(), + getRandomNumber(), color); case 2: - return new Rectangle(randomProperty, randomProperty, randomColor); + return new Rectangle(getRandomNumber(), getRandomNumber(), color); case 3: - return new RightTriangle(randomProperty, randomProperty, randomColor); + return new RightTriangle(getRandomNumber(), getRandomNumber(), color); default: - return new Square(randomProperty, randomColor); + return new Square(getRandomNumber(), color); } } - public GeometricFigure getDefaultFigure() { + + public Figure getDefaultFigure() { return new Circle(DEFAULT_RADIUS, DEFAULT_COLOR); } + + private int getRandomNumber() { + return random.nextInt(MAX_LENGTH); + } } diff --git a/src/main/java/core/basesyntax/GeometricFigure.java b/src/main/java/core/basesyntax/GeometricFigure.java deleted file mode 100644 index 8c627d59a5..0000000000 --- a/src/main/java/core/basesyntax/GeometricFigure.java +++ /dev/null @@ -1,17 +0,0 @@ -package core.basesyntax; - -public abstract class GeometricFigure implements Drawable, AreaCalculator { - protected String color; - - public GeometricFigure(String colour) { - this.color = colour; - } - - public String getColour() { - return color; - } - - public void setColour() { - this.color = color; - } -} diff --git a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java index 7ce1343941..f035a8e85f 100644 --- a/src/main/java/core/basesyntax/IsoscelesTrapezoid.java +++ b/src/main/java/core/basesyntax/IsoscelesTrapezoid.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class IsoscelesTrapezoid extends GeometricFigure { +public class IsoscelesTrapezoid extends Figure { private final int height; private final int firstBase; private final int secondBase; diff --git a/src/main/java/core/basesyntax/Rectangle.java b/src/main/java/core/basesyntax/Rectangle.java index 9feb14e313..130368cc78 100644 --- a/src/main/java/core/basesyntax/Rectangle.java +++ b/src/main/java/core/basesyntax/Rectangle.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class Rectangle extends GeometricFigure { +public class Rectangle extends Figure { private final int firstSide; private final int secondSide; diff --git a/src/main/java/core/basesyntax/RightTriangle.java b/src/main/java/core/basesyntax/RightTriangle.java index c70df9ff8c..e6a8e69d6e 100644 --- a/src/main/java/core/basesyntax/RightTriangle.java +++ b/src/main/java/core/basesyntax/RightTriangle.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class RightTriangle extends GeometricFigure { +public class RightTriangle extends Figure { private final int firstLeg; private final int secondLeg; diff --git a/src/main/java/core/basesyntax/Square.java b/src/main/java/core/basesyntax/Square.java index a425130f32..c63fdb2273 100644 --- a/src/main/java/core/basesyntax/Square.java +++ b/src/main/java/core/basesyntax/Square.java @@ -1,6 +1,6 @@ package core.basesyntax; -public class Square extends GeometricFigure { +public class Square extends Figure { private final int side; public Square(int side, String color) { From f3d8d666cd744d26b2f96bb45ffce28cc8706c57 Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Thu, 28 Sep 2023 18:41:57 +0300 Subject: [PATCH 08/10] Fixed style and main method --- src/main/java/core/basesyntax/ColorSupplier.java | 7 ++++--- src/main/java/core/basesyntax/FigureSupplier.java | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index 1fd5f96c18..0643b2cec5 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -4,9 +4,10 @@ public class ColorSupplier { private final Random random = new Random(); + Color[] colorSet = Color.values(); public String getRandomColor() { - int index = random.nextInt(Color.values().length); - return Color.values()[index].name(); + int index = random.nextInt(colorSet.length); + return colorSet[index].name(); } -} \ No newline at end of file +} diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index cdba0a4048..09b4d118c0 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -30,12 +30,14 @@ public Figure getRandomFigure() { } } - public Figure getDefaultFigure() { return new Circle(DEFAULT_RADIUS, DEFAULT_COLOR); } private int getRandomNumber() { + if (random.nextInt(MAX_LENGTH) == 0) { + return random.nextInt(MAX_LENGTH); + } return random.nextInt(MAX_LENGTH); } } From 8223f8c16fa37341af91a333fcd8b4f07188577d Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Thu, 28 Sep 2023 19:26:40 +0300 Subject: [PATCH 09/10] Fixed style and main method --- src/main/java/core/basesyntax/ColorSupplier.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index 0643b2cec5..d9f1d5c7c2 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -4,7 +4,7 @@ public class ColorSupplier { private final Random random = new Random(); - Color[] colorSet = Color.values(); + private final Color[] colorSet = Color.values(); public String getRandomColor() { int index = random.nextInt(colorSet.length); From 797aaf330379bee38d72840efed44bd50c70a27d Mon Sep 17 00:00:00 2001 From: Hlib Kulikov Date: Mon, 2 Oct 2023 10:51:16 +0300 Subject: [PATCH 10/10] Added fixes --- src/main/java/core/basesyntax/ColorSupplier.java | 6 +++--- src/main/java/core/basesyntax/Figure.java | 1 - src/main/java/core/basesyntax/FigureSupplier.java | 7 ++----- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/main/java/core/basesyntax/ColorSupplier.java b/src/main/java/core/basesyntax/ColorSupplier.java index d9f1d5c7c2..cb35171adc 100644 --- a/src/main/java/core/basesyntax/ColorSupplier.java +++ b/src/main/java/core/basesyntax/ColorSupplier.java @@ -4,10 +4,10 @@ public class ColorSupplier { private final Random random = new Random(); - private final Color[] colorSet = Color.values(); + private final Color[] colorArray = Color.values(); public String getRandomColor() { - int index = random.nextInt(colorSet.length); - return colorSet[index].name(); + int index = random.nextInt(colorArray.length); + return colorArray[index].name(); } } diff --git a/src/main/java/core/basesyntax/Figure.java b/src/main/java/core/basesyntax/Figure.java index eca3a05814..28c25f9f34 100644 --- a/src/main/java/core/basesyntax/Figure.java +++ b/src/main/java/core/basesyntax/Figure.java @@ -10,5 +10,4 @@ public Figure(String color) { public String getColor() { return color; } - } diff --git a/src/main/java/core/basesyntax/FigureSupplier.java b/src/main/java/core/basesyntax/FigureSupplier.java index 09b4d118c0..1c3b5ed579 100644 --- a/src/main/java/core/basesyntax/FigureSupplier.java +++ b/src/main/java/core/basesyntax/FigureSupplier.java @@ -6,7 +6,7 @@ public class FigureSupplier { private static final int MAX_LENGTH = 100; private static final int FIGURE_COUNT = 5; private static final int DEFAULT_RADIUS = 10; - private static final String DEFAULT_COLOR = String.valueOf(Color.WHITE); + private static final String DEFAULT_COLOR = Color.WHITE.name(); private final Random random = new Random(); private final ColorSupplier supplier = new ColorSupplier(); @@ -35,9 +35,6 @@ public Figure getDefaultFigure() { } private int getRandomNumber() { - if (random.nextInt(MAX_LENGTH) == 0) { - return random.nextInt(MAX_LENGTH); - } - return random.nextInt(MAX_LENGTH); + return random.nextInt(MAX_LENGTH - 1) + 1; } }