Calculator Conundrum

in #ita15 days ago

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);
}

}

Sort:  

Thank you, friend!
I'm @steem.history, who is steem witness.
Thank you for witnessvoting for me.
image.png
please click it!
image.png
(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.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 63123.52
ETH 3121.26
USDT 1.00
SBD 3.88