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 7b9b3b2

Browse files
Kyu 8 | Age Range Compatibility Equation
1 parent 30ab5c8 commit 7b9b3b2

File tree

4 files changed

+63
-1
lines changed

4 files changed

+63
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Kata Found realized
1919
- [A wolf in sheep's clothing](aWolfInSheepClothing)
2020

2121
- [Abbreviate a Two Word Name](abbreviateATwoWordName)
22-
-
22+
23+
- [Age Range Compatibility Equation](ageRangeCompatibilityEquation)
24+
2325
- [Find Nearest square number](findNearestSquareNumber)
2426

2527

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package kyu8.ageRangeCompatibilityEquation;
2+
3+
public class Kata {
4+
public static String datingRange(int age) {
5+
int min = 0;
6+
int max = 0;
7+
if (age < 14) {
8+
min = (int) (age - 0.10 * age);
9+
max = (int) (age + 0.10 * age);
10+
} else {
11+
min = (int) (age / 2) + 7;
12+
max = (int) (age - 7) * 2;
13+
}
14+
return min + "-" + max;
15+
}
16+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Age Range Compatibility Equation
2+
3+
Everybody knows the classic "half your age plus seven" dating rule that a lot of people follow (including myself). It's
4+
the 'recommended' age range in which to date someone.
5+
6+
<img src="https://user-images.githubusercontent.com/69739890/118407770-c771f680-b647-11eb-8202-202aeb02c545.png"/>
7+
8+
```minimum age <= your age <= maximum age``` #Task
9+
10+
Given an integer (1 <= n <= 100) representing a person's age, return their minimum and maximum age range.
11+
12+
This equation doesn't work when the age <= 14, so use this equation instead:
13+
14+
```java
15+
min = age - 0.10 * age
16+
max = age + 0.10 * age
17+
```
18+
19+
You should floor all your answers so that an integer is given instead of a float (which doesn't represent age). Return
20+
your answer in the form [min]-[max]
21+
22+
##Examples:
23+
24+
```java
25+
age = 27 => 20-40
26+
age = 5 => 4-5
27+
age = 17 => 15-20
28+
```
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package kyu8.ageRangeCompatibilityEquation;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
public class testKata {
8+
@Test
9+
public void exampleTests() {
10+
assertEquals("15-20", Kata.datingRange(17));
11+
assertEquals("27-66", Kata.datingRange(40));
12+
assertEquals("14-16", Kata.datingRange(15));
13+
assertEquals("24-56", Kata.datingRange(35));
14+
assertEquals("9-11", Kata.datingRange(10));
15+
}
16+
}

0 commit comments

Comments
(0)

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