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 b9d587f

Browse files
Kyu 8 | Basic Mathematical Operations
1 parent 4b584e5 commit b9d587f

File tree

5 files changed

+58
-0
lines changed

5 files changed

+58
-0
lines changed

‎pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,12 @@
2525
<artifactId>commons-math3</artifactId>
2626
<version>3.6.1</version>
2727
</dependency>
28+
<!-- https://mvnrepository.com/artifact/org.hamcrest/hamcrest-core -->
29+
<dependency>
30+
<groupId>org.hamcrest</groupId>
31+
<artifactId>hamcrest-core</artifactId>
32+
<version>1.3</version>
33+
<scope>test</scope>
34+
</dependency>
2835
</dependencies>
2936
</project>

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

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

3333
- [Array plus array](arrayPlusArray)
3434

35+
- [Basic Mathematical Operations](basicMathematicalOperations)
36+
3537
- [Find Nearest square number](findNearestSquareNumber)
3638

3739

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kyu8.basicMathematicalOperations;
2+
3+
public class BasicOperations {
4+
public static Integer basicMath(String op, int v1, int v2) {
5+
if (op == "+") {
6+
return v1 + v2;
7+
} else if (op == "-") {
8+
return v1 - v2;
9+
} else if (op == "*") {
10+
return v1 * v2;
11+
} else if (op == "/") {
12+
return v1 / v2;
13+
} else {
14+
return 0;
15+
}
16+
}
17+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Basic Mathematical Operations
2+
3+
Your task is to create a function that does four basic mathematical operations.
4+
5+
The function should take three arguments - operation(string/char), value1(number), value2(number).
6+
The function should return result of numbers after applying the chosen operation.
7+
8+
**Examples**
9+
10+
```java
11+
basicOp('+', 4, 7) // Output: 11
12+
basicOp('-', 15, 18) // Output: -3
13+
basicOp('*', 5, 5) // Output: 25
14+
basicOp('/', 49, 7) // Output: 7
15+
```
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kyu8.basicMathematicalOperations;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.hamcrest.CoreMatchers.is;
6+
import static org.hamcrest.MatcherAssert.assertThat;
7+
8+
public class testBasicOperations {
9+
@Test
10+
public void testBasics() {
11+
System.out.println("Basic Tests");
12+
assertThat(BasicOperations.basicMath("+", 4, 7), is(11));
13+
assertThat(BasicOperations.basicMath("-", 15, 18), is(-3));
14+
assertThat(BasicOperations.basicMath("*", 5, 5), is(25));
15+
assertThat(BasicOperations.basicMath("/", 49, 7), is(7));
16+
}
17+
}

0 commit comments

Comments
(0)

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