
import java.util.Scanner;
import javax.swing.JOptionPane;
/**
 * COP2210 Example
 * @author Bill Kraynek
 */
public class ClassExampleThree {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String university = new String("Florida International University");
        int pos2 = university.indexOf("I");
        int pos1 = university.indexOf('U');
        String initials = university.charAt(0) + university.substring(pos2, pos2 + 1) + university.substring(pos1, pos1 + 1);
        System.out.println(pos1 + " " + initials);
        int x = 5;
        System.out.println(x > 2);
        System.out.println(x > 5);
        System.out.println(x == 5);
        System.out.println(x <= 5);
        System.out.println("abc".equals("abc "));
        String line = "Here is  a new line  ";
        String part = line;
        String space = " ";
        while (true) {
            int spaceIndex = part.indexOf(" ");
            if (spaceIndex == -1) break;
            String word = part.substring(0, spaceIndex);
            System.out.println(">" + word + "<");
            part = part.substring(spaceIndex + 1);
        }// end while
        System.out.println(">" + part + "<");
        Scanner scanner = new Scanner(line);
        while (true) {
            if (!scanner.hasNext()) break;
            System.out.println(">" + scanner.next() + "< ");
        }
        line = JOptionPane.showInputDialog("Enter a line", "Here  is a new  line  ");
        if( line == null ) return;
        scanner = new Scanner(line);
        //scanner.useDelimiter("abc");
        //scanner.useDelimiter("[abc]");
        //scanner.useDelimiter("[abc]+");
        //scanner.useDelimiter("[^abc]+");
        scanner.useDelimiter("[^a-zA-Z]+");
        while (true) {
            if (!scanner.hasNext()) break;
            System.out.println(">" + scanner.next() + "< ");
        }
        int sum = 0;
        String accum = "0";
        while (true) {
            String input = JOptionPane.showInputDialog("Enter either add <num> or\nsub <num>\nClick cancel to quit.");
            if (input == null) break;
            Scanner inputScanner = new Scanner(input);
            String action = inputScanner.next();
            int num = inputScanner.nextInt();
            if( action.equals("add") ) {
                sum += num;
                accum += " + " + num;
            } else if( action.equals("sub") ) {
                sum -= num;
                accum += " - " + num;
            } else {
                    JOptionPane.showMessageDialog(null,action + " is not a valid operation");
            }// end if
        } // end while
        accum += " = " + sum;
        JOptionPane.showMessageDialog(null, accum);
    }
}

