import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.util.Scanner;

public class Example4 {
    
    public Example4() {
        // ArrayList is in java.util
        ArrayList<Person> people = new ArrayList<Person>();
        while( true ) {
            String name = JOptionPane.showInputDialog("Enter your full name. Click cancel or enter to quit.");
            if( name == null || name.equals("") ) break;
            Scanner s = new Scanner(name);
            String first = s.next();
            String last = "";
            while( s.hasNext() ) {
                last += s.next() + " ";
            } // end while
            // declare objects where they are first used if possible
            String idNumber = JOptionPane.showInputDialog("Enter your Social Sercurity Number.");
            while( idNumber == null ) {
                idNumber = JOptionPane.showInputDialog("You must Enter your Social Sercurity Number.");
            } // end while
            Person aPerson = new Person(idNumber,first,last);
            // add aPerson to the end of the ArrayList
            people.add(aPerson);
            JOptionPane.showMessageDialog(null,"Hi " + aPerson.getFirstName()+". How are you?");
        } // end while
        String output = "The full names are:\n";
        for( Person person : people ) {
            output += person + "\n";
        } // end for
        JOptionPane.showMessageDialog(null,output);
    } // end Example4()
    
    public static void main(String[] args) {
        new Example4();
        System.exit(0);
    } // end main
    
} // end Example4

