Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77b45ae

Browse files
Kyu 8 | Area Or Perimeter
1 parent 113f190 commit 77b45ae

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

‎src/main/java/kyu8/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Kata Found realized
2828

2929
- [Area of a Square](areaOfASquare)
3030

31+
- [Area or Perimeter](areaOrPerimeter)
32+
3133
- [Find Nearest square number](findNearestSquareNumber)
3234

3335

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Area or Perimeter
2+
3+
You are given the ```length``` and ```width``` of a 4-sided polygon. The polygon can either be a rectangle or a square.
4+
If it is a square, return its area. If it is a rectangle, return its perimeter.
5+
6+
```java
7+
area_or_perimeter(6, 10) --> 32
8+
area_or_perimeter(3, 3) --> 9
9+
```
10+
11+
Note: for the purposes of this kata you will assume that it is a square if its ```length``` and ```width``` are equal,
12+
otherwise it is a rectangle.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kyu8.areaOrPerimeter;
2+
3+
public class Solution {
4+
public static int areaOrPerimeter(int l, int w) {
5+
int result = 0;
6+
if (l == w) {
7+
result = l * l;
8+
} else {
9+
result = 2 * l + 2 * w;
10+
}
11+
return result;
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package kyu8.areaOrPerimeter;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testSolution {
8+
@Test
9+
public void testSomething() {
10+
assertEquals(16, Solution.areaOrPerimeter(4 , 4));
11+
assertEquals(32, Solution.areaOrPerimeter(6 , 10));
12+
}
13+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /