Skip to content

Commit

Permalink
done?
Browse files Browse the repository at this point in the history
  • Loading branch information
mizuo-san committed Jan 2, 2025
1 parent c26debc commit 00af0f2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public double area() {
@Override
public void draw() {
System.out.println("Figure: " + getName() + ", area: "
+ area() + ", radius: "
+ radius + ", color: " + getColor());
+ area() + " sq. units, radius: "
+ radius + " units, color: " + getColor());
}
}
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,9 +3,9 @@
import java.util.Random;

public class ColorSupplier {
Random picker = new Random();
private final static Random picker = new Random();

public Colors getRandomColor() {
public static Colors getRandomColor() {
return Colors.values()[picker.nextInt(Colors.values().length)];
}
}
2 changes: 2 additions & 0 deletions src/main/java/core/basesyntax/Figure.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public abstract class Figure {
private Colors color;
private String name;

public abstract void draw();

public Figure(Colors color, String name) {
this.color = color;
this.name = name;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/core/basesyntax/FigureMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

public interface FigureMethods {
double area();
void draw();
}
18 changes: 14 additions & 4 deletions src/main/java/core/basesyntax/FigureSupplier.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package core.basesyntax;

public class FigureSupplier {
public Figure getRandomFigure() {
import java.util.Random;

}
public class FigureSupplier extends ColorSupplier {
private final static Random picker = new Random();

public Figure getDefaultFigure() {
public static Figure getRandomFigure() {
return switch(picker.nextInt(4)) {
case 0 -> new Circle(getRandomColor(), picker.nextInt(1, 50));
case 1 -> new Rectangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50));
case 2 -> new RightTriangle(getRandomColor(), picker.nextInt(1, 50), picker.nextInt(1, 50));
case 3 -> new Square(getRandomColor(), picker.nextInt(1, 50));
default -> new Circle(Colors.WHITE, 10);
};
}

public static Figure getDefaultFigure() {
return new Circle(Colors.WHITE, 10);
}
}
20 changes: 20 additions & 0 deletions src/main/java/core/basesyntax/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

public class Main {
public static void main(String args[]) {
printArray();
}

public static Figure[] listOfRandomFigures() {
Figure[] array = new Figure[6];

for(int i = 0; i < 3; i++) {
array[i] = FigureSupplier.getRandomFigure();
}

for(int i = 3; i < 6; i++) {
array[i] = FigureSupplier.getDefaultFigure();
}

return array;
}

public static void printArray() {
for(Figure i : listOfRandomFigures()) {
i.draw();
}
}
}
6 changes: 3 additions & 3 deletions src/main/java/core/basesyntax/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public double area() {
@Override
public void draw() {
System.out.println("Figure: " + getName() + ", area: "
+ area() + ", firstSide: "
+ firstSide + ", secondSide: "
+ secondSide + ", color: " + getColor());
+ area() + " sq. units, firstSide: "
+ firstSide + " units, secondSide: "
+ secondSide + " units, color: " + getColor());
}
}

0 comments on commit 00af0f2

Please sign in to comment.