Skip to content

Commit

Permalink
Deleted interface AreaCalculator, transfered method getArea() to clas…
Browse files Browse the repository at this point in the history
…s Figure
  • Loading branch information
andriy-linkov committed Nov 8, 2024
1 parent 4a2f741 commit 8d0c8f3
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
5 changes: 0 additions & 5 deletions src/main/java/core/basesyntax/AreaCalculator.java

This file was deleted.

12 changes: 6 additions & 6 deletions src/main/java/core/basesyntax/Circle.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public Circle(Color color, double radius) {
this.radius = radius;
}

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

@Override
public void draw() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Figure: circle, ")
.append("area: ").append(getArea()).append(" sq.units, ")
.append("radius: ").append(radius).append(" units, ")
.append("color: ").append(color);
.append("color: ").append(color.name());
System.out.println(stringBuilder.toString());
}

@Override
protected double getArea() {
return Math.PI * radius * radius;
}
}
4 changes: 3 additions & 1 deletion src/main/java/core/basesyntax/Figure.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package core.basesyntax;

public abstract class Figure implements AreaCalculator, Drawable {
public abstract class Figure implements Drawable {
protected Color color;

public Figure(Color color) {
this.color = color;
}

protected abstract double getArea();
}
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 @@ -12,12 +12,6 @@ public IsoscelesTrapezoid(Color color, double leg, double firstBase, double seco
this.secondBase = secondBase;
}

@Override
public double getArea() {
double h = Math.sqrt(Math.pow(leg, 2.0) - Math.pow((firstBase - secondBase), 2.0) / 4.0);
return (firstBase + secondBase) * h / 2.0;
}

@Override
public void draw() {
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -26,8 +20,14 @@ public void draw() {
.append("leg: ").append(leg).append(" units, ")
.append("firstBase: ").append(firstBase).append(" units, ")
.append("secondBase: ").append(secondBase).append(" units, ")
.append("color: ").append(color);
.append("color: ").append(color.name());

System.out.println(stringBuilder.toString());
}

@Override
protected double getArea() {
double h = Math.sqrt(Math.pow(leg, 2.0) - Math.pow((firstBase - secondBase) / 2.0, 2.0));
return (firstBase + secondBase) * h / 2.0;
}
}
12 changes: 6 additions & 6 deletions src/main/java/core/basesyntax/Rectangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public Rectangle(Color color, double length, double width) {
this.width = width;
}

@Override
public double getArea() {
return length * width;
}

@Override
public void draw() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Figure: rectangle, ")
.append("area: ").append(getArea()).append(" sq.units, ")
.append("length: ").append(length).append(" units, ")
.append("width: ").append(width).append(" units, ")
.append("color: ").append(color);
.append("color: ").append(color.name());
System.out.println(stringBuilder.toString());
}

@Override
protected double getArea() {
return length * width;
}
}
12 changes: 6 additions & 6 deletions src/main/java/core/basesyntax/RightTriangle.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ public RightTriangle(Color color, double firstLeg, double secondLeg) {
this.secondLeg = secondLeg;
}

@Override
public double getArea() {
return firstLeg * secondLeg / 2.0;
}

@Override
public void draw() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Figure: right triangle, ")
.append("area: ").append(getArea()).append(" sq.units, ")
.append("firstLeg: ").append(firstLeg).append(" units, ")
.append("secondLeg: ").append(secondLeg).append(" units, ")
.append("color: ").append(color);
.append("color: ").append(color.name());
System.out.println(stringBuilder.toString());
}

@Override
protected double getArea() {
return firstLeg * secondLeg / 2.0;
}
}
12 changes: 6 additions & 6 deletions src/main/java/core/basesyntax/Square.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ public Square(Color color, double side) {
this.side = side;
}

@Override
public double getArea() {
return side * side;
}

@Override
public void draw() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("Figure: square, ")
.append("area: ").append(getArea()).append(" sq.units, ")
.append("side: ").append(side).append(" units, ")
.append("color: ").append(color);
.append("color: ").append(color.name());
System.out.println(stringBuilder.toString());
}

@Override
protected double getArea() {
return side * side;
}
}

0 comments on commit 8d0c8f3

Please sign in to comment.