Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. public class RPNevaluator {
  2.     private StringBuffer outputBuffer;
  3.     private Stack <Double> myStack = new Stack <Double> ();
  4.  
  5.     RPNevaluator( String inputString ) {
  6.         outputBuffer = new StringBuffer();
  7.         StringTokenizer sTok = new StringTokenizer ( inputString, "+-/* ", true);
  8.         String temp;
  9.        
  10.         while (sTok.hasMoreTokens()) {
  11.             temp = ( String ) sTok.nextElement();
  12.             switch ( temp.charAt(0)) {
  13.             case '+':
  14.                 double valueA = ( myStack.pop() + " " );
  15.                 double valueB = ( myStack.pop() + " " );
  16.                
  17.                 myStack.push(temp);
  18.                 break;
  19.             case '-':
  20.                 outputBuffer.append( myStack.pop() + " " );
  21.                 myStack.push(temp);
  22.                 break;
  23.             case '*':
  24.                 outputBuffer.append( myStack.pop() + " " );
  25.                 myStack.push(temp);
  26.                 break;
  27.             case '/':
  28.                 outputBuffer.append( myStack.pop() + " " );
  29.                 myStack.push(temp);
  30.                 break;
  31.             case ' ':
  32.                 break;
  33.             default:
  34.                 outputBuffer.append( temp +  " " );
  35.                 break;
  36.             }
  37.         }
  38.     }
  39.     public static void main(String[] args) {
  40.  
  41.     }
  42.  
  43. }
  44.  
  45.  
  46. // Operator Button Stuff
  47. // opButtons cannot be done using a loop because their names aren't able to be sequenced. Need to initialize manually
  48.         opButton[0] = new JButton ("+");
  49.         opButton[1] = new JButton ("-");
  50.         opButton[2] = new JButton ("*");
  51.         opButton[3] = new JButton ("/");
  52.  
  53. [Skip a bunch of lines]
  54.  
  55. // (WIP) Operator buttons
  56.         // Each operator stores the data before it in a stack
  57.         // Clear display screen to allow addition of new data
  58.         for(int c = 0; c < opButton.length; c++){
  59.             if (evt.getSource()== opButton[c]){
  60.                 display.setText(display.getText()+numButton[c].getText());
  61.             } // End of if statement
  62.         } // End of for loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement