Casting a primitive type into an operator....
Hello, I'm working on an assignment for my programming class which involves reading a mathematical expression from the user, checking to see if parentheses are balanced, changing the expression to postifx expression, and finally evaluate the postfix expression and print the result.
It's the last part that I'm currently stuck in. So far the program does everything but the evaluation, which is actually not a difficult process. Here is my code so far:
void ReversePostfixNotation()
{
stk.clear();
Scanner sc =new Scanner(postfix);
int t1 = -1;
int t2 = -1;
int t3 = -1;
try
{
while(sc.hasNext())
{
String current = sc.next();
if(isNumber(current))
{
stk.push(current);
}
elseif(isOperator(current.charAt(0)))
{
char operator = current.charAt(0);
t1 = Integer.parseInt((String) stk.pop());
t2 = Integer.parseInt((String) stk.pop());
// STUCK HERE
// Need to have: t2 (operator) t1
}
}
}
Where the STUCK HERE comment is written, I need to be able to cast the operator primitive type into an ACTUAL operator. All the other methods used are written and working, and the operator variable is guaranteed to be either +,-,/, or *.
Thanks in advance, let me know if I can clear anything else up.

