Now you are going to make a simple calculator.
The expression will be like this: n {symbol} m = {return value};
Example:
int result = calculate(4, 5, +); // 4 + 5 = 9;
Symbols are +, -, *.
public class calculator {
public static int calculate(int n, int m, char symbol) {
// do your best :)
int result = 0;
switch(symbol) {
case '+':
result = n + m;
break;
case '-':
result = n - m;
break;
case '*':
result = n * m;
break;
}
return result;
}
}
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import org.junit.runners.JUnit4;
// TODO: Replace examples and use TDD by writing your own tests
public class SolutionTest {
@Test
public void testSomething() {
assertEquals(9, calculator.calculate(4, 5, '+'));
assertEquals(7, calculator.calculate(12, 5, '-'));
assertEquals(60, calculator.calculate(20, 3, '*'));
}
}