Calculator Conundrum
class CalculatorConundrum {
public String calculate(int operand1, int operand2, String operation) {
if (operation == null) {throw new IllegalArgumentException ("Operation cannot be null");}
if(operation.equals("")) {throw new IllegalArgumentException ("Operation cannot be empty");}
double total =0;
try{switch(operation){
case "+":
total = operand1+operand2;
break;
case "-":
total = operand1-operand2;
break;
case "*":
total = operand1*operand2;
break;
case "/":
total = operand1/operand2;
break;
default:
throw new IllegalOperationException (String.format("Operation '%s' does not exist", operation));
}
} catch(ArithmeticException e){throw new IllegalOperationException("Division by zero is not allowed",e);}
return String.format("%s %s %s = %d", operand1, operation, operand2, (int)total);
}
}
Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
please click it!
(Go to https://steemit.com/~witnesses and type fbslo at the bottom of the page)
The weight is reduced because of the lack of Voting Power. If you vote for me as a witness, you can get my little vote.