Skip to content

Commit

Permalink
did fixes with structure code
Browse files Browse the repository at this point in the history
  • Loading branch information
Vladlesn committed Oct 6, 2023
1 parent 64f2fcc commit d6ab8ab
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import java.util.Random;

public class ColorSupplier {
private final Colors[] colors = Colors.values();
private final Random random = new Random();

public String getRandomColor() {
return colors[random.nextInt(colors.length)].name();
int index = random.nextInt(Colors.values().length);
return Colors.values()[index].toString();
}
}
11 changes: 6 additions & 5 deletions src/main/java/core/basesyntax/FigureSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
import java.awt.Shape;
import java.util.Random;

public class FigureSupplier {
private final int vaultOfClasses = 5;
public final class FigureSupplier {
public static final int RADIUS = 10;
public static final int FIGURE_COUNT = 5;
private final Random random = new Random();
private final ColorSupplier colorSupplier = new ColorSupplier();

public Figure getRandomFigure() {
String color = colorSupplier.getRandomColor();
int randomValue = random.nextInt(vaultOfClasses);
int index = random.nextInt(5);
int randomValue = random.nextInt(FIGURE_COUNT);
int index = random.nextInt(FIGURE_COUNT);
Shape shape;
switch (index) {
case 0:
Expand All @@ -34,6 +35,6 @@ public Figure getRandomFigure() {
}

public Figure getDefaultFigure() {
return new Circle("White", 10);
return new Circle("White", RADIUS);
}
}
13 changes: 6 additions & 7 deletions src/main/java/core/basesyntax/HelloWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@

public class HelloWorld {
public static void main(String[] args) {
final int radius = 15;
FigureSupplier figureSupplier = new FigureSupplier();
Figure figure1 = figureSupplier.getRandomFigure();
Figure figure2 = figureSupplier.getRandomFigure();
Figure figure3 = figureSupplier.getRandomFigure();
Figure figure4 = figureSupplier.getDefaultFigure();
Figure figure5 = new Circle("Black", 15);
Figure[] figures = new Figure[]{figure1, figure2, figure3, figure4, figure5};
Figure[] figures = new Figure[5];
for (int i = 0; i <= 4; i++) {
figures[i] = figureSupplier.getRandomFigure();
}
figures[5] = new Circle("Black", radius);
for (Figure figure : figures) {
figure.draw();
}
}
}

14 changes: 7 additions & 7 deletions src/main/java/core/basesyntax/IsoscelesTrapezoid.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@

public class IsoscelesTrapezoid extends Figure {
private int height;
private int alenght;
private int blenght;
private int lenght1;
private int lenght2;

public IsoscelesTrapezoid(String color, int height, int alenght, int blenght) {
super(color);
this.height = height;
this.alenght = alenght;
this.blenght = blenght;
this.lenght1 = alenght;
this.lenght2 = blenght;
}

public double getArea() {
return (alenght + blenght) * height;
return (lenght1 + lenght2) * height;
}

@Override
public void draw() {
System.out.println("Figure: isosceles trapezoid, " + " area: "
+ getArea() + "," + " height: "
+ height + "," + " a length: " + alenght + "," + " b lenght: "
+ blenght + "," + " color: " + super.getColor());
+ height + "," + " a length: " + lenght1 + "," + " b lenght: "
+ lenght2 + "," + " color: " + super.getColor());
}
}

0 comments on commit d6ab8ab

Please sign in to comment.