Skip to content

Commit

Permalink
added random color, random area and so on
Browse files Browse the repository at this point in the history
  • Loading branch information
bagouser123 committed Oct 5, 2023
1 parent b7bbafd commit 0e93e7c
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 22 deletions.
14 changes: 8 additions & 6 deletions src/main/java/core/basesyntax/Circle.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package core.basesyntax;

public class Circle implements Figure {
private String color;
public class Circle extends Figure {
private double radius;

public Circle(String color, double radius) {
this.color = color;
super(color);
this.radius = radius;
}

@Override
public double getArea() {
public double getArea() {
return Math.PI * radius * radius;
}

@Override
public void draw() {
System.out.println("Figure circle,area " + getArea() + "sq.units,radius:"
+ radius + "units, color:" + color);
System.out.println("Figure: circle, area: " + getArea()
+ " sq. units, radius: " + radius + " units, color: " + getColor());
}

// Інші методи, специфічні для кола
}
2 changes: 1 addition & 1 deletion src/main/java/core/basesyntax/ColorSupplier.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
public class ColorSupplier {
private static final String[] COLORS = {"red", "blue", "green", "yellow", "purple", "orange"};

public String getRandomColor() {
public String getRandomColor(){
Random random = new Random();
int index = random.nextInt(COLORS.length);
return COLORS[index];
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/core/basesyntax/Figure.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package core.basesyntax;

public interface Figure {
public abstract class Figure {
private String color;

double getArea();
public Figure(String color) {
this.color = color;
}

void draw();
}
public String getColor() {
return color;
}

public abstract double getArea();
public abstract void draw();
}
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/IsoscelesTrapezoid.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package core.basesyntax;

public class IsoscelesTrapezoid implements Figure {
public class IsoscelesTrapezoid extends Figure {
private String color;
private double upperBase;
private double lowerBase;
private double height;

public IsoscelesTrapezoid(String color, double upperBase, double lowerBase, double height) {
this.color = color;
super(color);
this.upperBase = upperBase;
this.lowerBase = lowerBase;
this.height = height;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/core/basesyntax/Rectangle.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package core.basesyntax;

public class Rectangle implements Figure {
private String color;
public class Rectangle extends Figure {
private double length;
private double width;

public Rectangle(String color, double length, double width) {
this.color = color;
super(color);
this.length = length;
this.width = width;
}
Expand All @@ -18,7 +17,8 @@ public double getArea() {

@Override
public void draw() {
System.out.println("Figure rectangle,area:" + getArea() + "sq.units,length:"
+ length + "units,width:" + width + "units,color:" + color);
System.out.println("Figure: rectangle, area: " + getArea()
+ " sq. units, length: " + length
+ " units, width: " + width + " units, color: " + getColor());
}
}
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/RightTriangle.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package core.basesyntax;

public class RightTriangle implements Figure {
public class RightTriangle extends Figure {
private String color;
private double base;
private double height;

public RightTriangle(String color, double base, double height) {
this.color = color;
super(color);
this.base = base;
this.height = height;

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/core/basesyntax/Square.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package core.basesyntax;

public class Square implements Figure {
public class Square extends Figure {
private String color;
private double sideLength;

public Square(String string, double sideLength) {
this.color = string;
super(string);
this.sideLength = sideLength;
}

Expand Down

0 comments on commit 0e93e7c

Please sign in to comment.