public static double evaluate(String expression) { Stack stack = new Stack(); double first = 0.0; double second = 0.0; StringTokenizer tokenizer; tokenizer = new StringTokenizer (expression); while (tokenizer.hasMoreTokens()) { char word = tokenizer.nextToken().charAt(0); if(word == '+' || word == '-' || word == '*' || word == '/') { first = Double.parseDouble(stack.pop().toString()); second = Double.parseDouble(stack.pop().toString()); } switch (word) { case '+': stack.push(new Double(first + second)); break; case '-': stack.push(new Double(second - first)); break; case '*': stack.push(new Double(first * second)); break; case '/': stack.push(new Double(second / first)); break; default: stack.push(new Double(word - '0')); break; } } // finish this method return Double.parseDouble(stack.pop().toString());// change the 0.0 to the answer off of the stack }// end evaluate