Skip to content

Instantly share code, notes, and snippets.

@AnasAlmasri
Created April 21, 2019 04:27
Show Gist options
  • Save AnasAlmasri/3bf166e03625dc40d4083d6f495bc976 to your computer and use it in GitHub Desktop.
Save AnasAlmasri/3bf166e03625dc40d4083d6f495bc976 to your computer and use it in GitHub Desktop.
// method to loop through results trying to find an operator
private char getOperatorFromResult(ArrayList<String> results) {
for (String str : results) {
if (getCharOperatorFromText(str) != '0') {
return getCharOperatorFromText(str);
}
}
return '0';
}
// method to convert string operator to char
private char getCharOperatorFromText(String strOper) {
switch (strOper) {
case "plus":
case "add":
return '+';
case "minus":
case "subtract":
return '-';
case "times":
case "multiply":
return '*';
case "divided by":
case "divide":
return '/';
case "power":
case "raised to":
return '^';
}
return '0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment