10000 Kyu 8 | Area Of a Square · danielex1999/CodeWars-Java@6ff9a19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ff9a19

Browse files
committed
Kyu 8 | Area Of a Square
1 parent c42577d commit 6ff9a19

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

pom.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
<scope>test</scope>
2222
</dependency>
2323
<dependency>
24-
<groupId>junit</groupId>
25-
<artifactId>junit</artifactId>
26-
<version>3.8.1</version>
27-
<scope>test</scope>
24+
<groupId>org.apache.commons</groupId>
25+
<artifactId>commons-math3</artifactId>
26+
<version>3.6.1</version>
2827
</dependency>
2928
</dependencies>
3029
</project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package kyu8.areaOfASquare;
2+
3+
import org.apache.commons.math3.util.Precision;
4+
5+
public class Geometry {
6+
public static double squareArea(double A) {
7+
double result = Math.pow(2 * A / Math.PI, 2);
8+
return Precision.round(result, 2);
9+
}
10+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Area of a Square
2+
3+
Complete the function that calculates the area of the red square, when the length of the circular arc ```A``` is given
4+
as the input. Return the result rounded to two decimals.
5+
6+
<img src="https://user-images.githubusercontent.com/69739890/118408122-a27e8300-b649-11eb-97cb-e04b4519362c.png"/>
7+
8+
Note: use the π value provided in your language (```Math::PI```, ```M_PI```, ```math.pi```, etc)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package kyu8.areaOfASquare;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testGeometry {
8+
private static final double DELTA = 1e-15;
9+
@Test
10+
public void basicTests() {
11+
assertEquals(1.62, Geometry.squareArea(2),DELTA);
12+
assertEquals(0, Geometry.squareArea(0),DELTA);
13+
assertEquals(80, Geometry.squareArea(14.05),DELTA);
14+
}
15+
}

0 commit comments

Comments
 (0)
0