I have a few suggestions, but the most important point is the one Stephan has already made: you do not want to iterate the stack.
Firstly, unless you have been explicitly told to name it as such, "Program1" is a terrible name for a class. There's actually no need to have separate class just to kick off the program, in my opinion: Stick the main method in your ReversePolish class. (A better name might be RPNCalculator.)
How about defining an interface for a Stack, and having another class, LinkedStack, that implements that interface? That way you can code against an interface rather than an implementation. (As Campbell suggested, you should make these generic types: e.g. Stack<E>. If you haven't covered generics yet, though, don't worry about using type parameters.) For bonus points, list the pre- and post-conditions, return types (and, if you're comfortable with them, exceptions) for each of the interface methods. Doing this will help you better understand Stack's methods, and why they should have the return types they do. e.g. for push(E obj), you could have:
Preconditions:
stack is not empty
postconditions:
stack size is decreased by 1top item of stack is returnedthe rest of the stack is unchanged
returns the element on the top of the stack
throws StackException if stack is empty
LinkedStack then implements Stack (or, if using generics: LinkedStack<E> implements Stack<E>), and should have a private member variable of type Node (or Node<E>), representing the top of the stack (thus you could call it top). If you wanted to type-parameterise your Node class, instead of having
You would have
This generic version is far more reusable, as it is type-parameterised: it can objects of any type, not just Strings.
Rather than just using a String array of operators, why not use an enum? Here's a partial sample of what it might look like:
That way, in your RPNCalculator class, you can say:
Your ReversePolish class (which, again, I'd rename to RPNCalculator for better descriptiveness) is overly simple. Bear in mind that you want to handle ints and operators very differently: With ints you simply want to pop them on to the stack, with operators, you want to pop the next two items off the stack and apply the operator to them. So, how about a couple of methods: public void handleInt(int i) and public void handleOperator(Operator op)?
I don't want to give you too much help on this, but hopefully I've given you some ideas to move you forward. I think you're still a wee bit away from a decent solution, though, so feel free to ask further questions.