import java.util.Scanner;
import javax.swing.JOptionPane;
/*
 * NumberOperations.java
 *
 * Created on January 25, 2006, 1:51 PM
 *
 */

/**
 *
 * @author Bill Kraynek
 */
public class NumberOperations {
    
    /** Creates a new instance of NumberOperations */
    public NumberOperations() {
        int result = 0;
        while( true ) {
            String input = JOptionPane.showInputDialog("Enter an operation (add or subtract) and a number separated by a space");
            if( input == null ) break;
            Scanner scan = new Scanner(input);
            String operation = scan.next();
            int number = scan.nextInt();
            if( operation.equals("add") ) {
                result = result + number;
            }// end if
            if( operation.equals("subtract") )  {
                // this uses the -= operator which is equivalent to result = result - number;
                result -= number;
            }// end if
        }// end while
        String out = "Result of the operations is " + result;
        JOptionPane.showMessageDialog(null,out);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new NumberOperations();
    }
    
}

