android - How to regularly update an an integer -
so have string[] contains math expressions "3+6=" or "5+9/8=". have function gets array, loops through array , while looping, splits array have 1 string[] containing math operations +,-,*,/ , int[] containing numbers in question.
the function puts the answer int[] called answers. question why when output answers[0], can see first number , not answer first question?
edit = have found out problem happening. happening in evaluation method. dont know why:
public int evaluateanswertwooperations(string operation, int numberone, int numbertwo) { switch(operation){ case "+": log.d("usingsubtraction","plus2nmbers"); return numberone + numbertwo; case "-": log.d("usingsubtraction","usingsubtraction"); return numberone - numbertwo; case "/": log.d("usingsubtraction","usingdivision"); return numberone / numbertwo; default: log.d("usingsubtraction","usingmultiplication"); return numberone*numbertwo; }
something this:
import android.util.log; public class twonumberoperation { private final string plus = "+"; private final string minus = "-"; private final string multiply = "*"; private final string divide = "/"; private final string equal = "="; private string operation; private int numberone; private int numbertwo; public twonumberoperation(string operation, int numberone, int numbertwo) { if (operation.equalsignorecase(plus) || operation.equalsignorecase(minus) || operation.equalsignorecase(multiply) || operation.equalsignorecase(divide)) { this.operation = operation; this.numberone = numberone; this.numbertwo = numbertwo; } else { log.d("error", "error: invalid operation"); this.operation = ""; this.numberone = 0; this.numbertwo = 0; } } public int getanswer() { switch (operation) { case plus: log.d("addition", "addition"); return numberone + numbertwo; case minus: log.d("subtraction", "subtraction"); return numberone - numbertwo; case multiply: log.d("multiplication", "multiplication"); return numberone / numbertwo; case divide: log.d("division", "division"); return numberone / numbertwo; // note returning int default: log.d("error", "error"); return -999999999; } } @override public string tostring() { return numberone + operation + numbertwo + equal; } }
Comments
Post a Comment