Skip to content
Snippets Groups Projects

Pretty cool branch

Open Alexander Gatland requested to merge veb/devops-workshop:pretty_cool_branch into master
3 files
+ 39
4
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -39,6 +39,8 @@ public class CalculatorResource {
*/
if(expressionTrimmed.matches("[0-9]+[+][0-9]+")) result = sum(expressionTrimmed);
else if(expressionTrimmed.matches("[0-9]+[-][0-9]+")) result = subtraction(expressionTrimmed);
else if(expressionTrimmed.matches("[0-9]+[*][0-9]+")) result = multiplication(expressionTrimmed);
else if(expressionTrimmed.matches("[0-9]+[/][0-9]+")) result = division(expressionTrimmed);
return result;
}
@@ -70,4 +72,32 @@ public class CalculatorResource {
return number1 - number2;
}
/**
* Method used to calculate a multiplication expression.
* @param expression the expression to be calculated as a String
* @return the answer as an int
*/
public int multiplication(String expression){
String[] split = expression.split("[*]");
int number1 = Integer.parseInt(split[0]);
int number2 = Integer.parseInt(split[1]);
return number1 * number2;
}
/**
* Method used to calculate a division expression.
* @param expression the expression to be calculated as a String
* @return the answer as an int
*/
public int division(String expression){
String[] split = expression.split("[/]");
int number1 = Integer.parseInt(split[0]);
int number2 = Integer.parseInt(split[1]);
return number1 / number2;
}
}
Loading