Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RPNevaluator {
- private StringBuffer outputBuffer;
- private Stack <Double> myStack = new Stack <Double> ();
- RPNevaluator( String inputString ) {
- outputBuffer = new StringBuffer();
- StringTokenizer sTok = new StringTokenizer ( inputString, "+-/* ", true);
- String temp;
- while (sTok.hasMoreTokens()) {
- temp = ( String ) sTok.nextElement();
- switch ( temp.charAt(0)) {
- case '+':
- double valueA = ( myStack.pop() + " " );
- double valueB = ( myStack.pop() + " " );
- myStack.push(temp);
- break;
- case '-':
- outputBuffer.append( myStack.pop() + " " );
- myStack.push(temp);
- break;
- case '*':
- outputBuffer.append( myStack.pop() + " " );
- myStack.push(temp);
- break;
- case '/':
- outputBuffer.append( myStack.pop() + " " );
- myStack.push(temp);
- break;
- case ' ':
- break;
- default:
- outputBuffer.append( temp + " " );
- break;
- }
- }
- }
- public static void main(String[] args) {
- }
- }
- // Operator Button Stuff
- // opButtons cannot be done using a loop because their names aren't able to be sequenced. Need to initialize manually
- opButton[0] = new JButton ("+");
- opButton[1] = new JButton ("-");
- opButton[2] = new JButton ("*");
- opButton[3] = new JButton ("/");
- [Skip a bunch of lines]
- // (WIP) Operator buttons
- // Each operator stores the data before it in a stack
- // Clear display screen to allow addition of new data
- for(int c = 0; c < opButton.length; c++){
- if (evt.getSource()== opButton[c]){
- display.setText(display.getText()+numButton[c].getText());
- } // End of if statement
- } // End of for loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement