Skip to content
Snippets Groups Projects
Commit 3f0d9fb1 authored by Martin Dolmen Helmersen's avatar Martin Dolmen Helmersen
Browse files

Progress method in CalculatorResource

parent 384191f8
No related branches found
No related tags found
No related merge requests found
...@@ -51,25 +51,36 @@ public int calculate(String expression) { ...@@ -51,25 +51,36 @@ public int calculate(String expression) {
public int multiplication(String equation) { public int multiplication(String equation) {
String[] split = equation.split("[*]"); String[] split = equation.split("[*]");
int sum = 0; int sum = Integer.parseInt(split[0]);
for (int i = 0; i < split.length; i++) { try{
for (int i = 1; i < split.length; i++) {
if(!(split[i]).equals("0")) {
sum *= Integer.parseInt(split[i]); sum *= Integer.parseInt(split[i]);
}else throw new IllegalArgumentException(" Number can't be zero");
} }
return sum; return sum;
}catch(IllegalArgumentException e){
e.printStackTrace();
}return -1;
} }
public int division(String equation){ public int division(String equation){
String[] split = equation.split("[/]"); String[] split = equation.split("[/]");
try{ try{
int sum = 0; int sum = Integer.parseInt(split[0]);
for (int i = 0; i < split.length; i++) { for (int i = 1; i < split.length; i++) {
if(!(split[i]).equals("0")){
sum = Integer.parseInt(split[i]); sum = Integer.parseInt(split[i]);
}else throw new IllegalArgumentException("Number can't be zero");
} }
return sum; return sum;
}catch (DivisionByZeroExceptionStub e){ }catch (IllegalArgumentException e){
} e.printStackTrace();
}return -1;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment