UNB/ CS/ David Bremner/ teaching/ java/ RPNStack.java
public class RPNStack extends VecStack{
    public RPNStack(){
        super();
    }
    public String process(String arg){
        if (arg.equals("Enter")){
            return (String)top();
        }

        if (isOperator(arg)){
            String right=(String)pop();
            String left=(String)pop();

            push(eval(arg,left,right));
        } else {
            push(arg);
        }
        return (String)top();
    }

    private String eval(String op,String left,  String right){
        double l=Double.parseDouble(left);
        double r=Double.parseDouble(right);
        double result=0;
        
        switch(op.charAt(0)){
        case '+':
            result=(l+r);
            break;
        case '-':
            result=l-r;
            break;
        case '*':
            result=l*r;
            break;
        case '/':
            result=l/r;
        }
        return Double.toString(result);
    }


    private boolean isOperator(String text){
        return !('0' <= text.charAt(0) && text.charAt(0) <= '9');
    }
}
//