dimanche 8 février 2015

How would I calculate the answer to the math questions with 3 integers and random operators? Android

I am creating a simple math game in android which has 2 levels. The question has random operators and random numbers/operands. How would I calculate the answer to the questions with 3 integers? With the switch statement below with the operators, it works with the two integers but how would I make it also work with 3 integers baring in mind it will be have random operators such as 2*4+3.



switch(level){
case LEVEL_EASY:
question.setText(operand1+" "+operators[operator]+" "+operand2);
break;
case LEVEL_HARD:
question.setText(operand1+" "+operators[operator1]+" "+operand2+" "+operators[operator2]+" "+operand3);
break;
default:
break;
}

switch(operator){
case ADD_OPERATOR:
answer = operand1+operand2;
break;
case SUBTRACT_OPERATOR:
answer = operand1-operand2;
break;
case MULTIPLY_OPERATOR:
answer = operand1*operand2;
break;
case DIVIDE_OPERATOR:
answer = operand1/operand2;
break;
default:
break;
}


Thank you!





Aucun commentaire:

Enregistrer un commentaire