UNB/ CS/ David Bremner/ teaching/ java/ RPNConsole.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal;
public class RPNConsole{

    public static void main(String[] args) throws IOException{
        BufferedReader reader = 
               new BufferedReader(new InputStreamReader(System.in)); 
        RPNStack2 stack=new RPNStack2();

        boolean quit=false;
        while(!quit){
            System.out.print(">>");
            String input=reader.readLine();
            if (input.charAt(0)=='q'){
                quit=true;
            } else {
                try{
                    BigDecimal result;
                    stack.process(input);
                    result=(BigDecimal)stack.top();
                    System.out.println(result);
                } 
                catch (EmptyStackException e){
                    System.out.println("Stack Underflow");
                }
                catch (NumberFormatException e){
                    System.out.println("Illegal number");
                }
                catch (DivideByZeroException e){
                    System.out.println("Divide by zero");
                }
                    
            }
        }
    }
}