/**
 * Test Vector Operations
 *
 * A sample program to test the basic Vector class
 * operations.
 */

import java.util.*;
import javabook.*;

public class TestVector
{
    
    public static void main( String[] args )
    {
        
        MainWindow  mainWindow;
        OutputBox     outputBox;
        InputBox    inputBox;  
        
        mainWindow = new MainWindow("Process Person Program");
        outputBox  = new OutputBox( mainWindow );
        inputBox   = new InputBox ( mainWindow );
                
        mainWindow.setVisible( true ); 
        outputBox.setVisible( true );
        
        //------------- Vector of Person --------------//
        Vector         friends;
        Person         person, p;
        Enumeration    enum;
        
        friends = new Vector( );
        
        person = new Person("jane", 10, 'F');  //Add four Person
        friends.add( person );
        
        person = new Person("jack",  6, 'M');
        friends.add( person );
        
        person = new Person("jill",  8, 'F');
        friends.add( person );
        
        person = new Person("john", 14, 'M');
        friends.add( person );
                
        //List Person objects in the vector
        
        outputBox.printLine("Contents of friends vector");
        outputBox.skipLine( 1 );
        
        enum = friends.elements( );
        
        while ( enum.hasMoreElements( ) ) {
        
            p = (Person) enum.nextElement( );
        
            outputBox.printLine( p.getName( ) );
        }
        
        outputBox.skipLine( 2 );
        
        //Remove the second element at index 1
        friends.remove( 1 ); 
        
        
        //List the vector contents again
        
        outputBox.printLine("Contents of friends vector");
        outputBox.skipLine( 1 );
        
        enum = friends.elements( );
        
        while ( enum.hasMoreElements( ) ) {
        
            p = (Person) enum.nextElement( );
        
            outputBox.printLine( p.getName( ) );
        }

        outputBox.skipLine( 2 );
        
        //-------------- More sample operations --------------//
        
        Vector vector = new Vector(5, 3 ); //initial size of 5
                                           //increment by 3 elements
        
        for (int i = 0; i < 15; i++) {
            
            System.out.println( vector.capacity( ) + "   " + vector.size( ) );
            
            vector.add( "String " + i );
        }
        
        String s = (String) vector.elementAt( 5 );
        
        outputBox.printLine( "Direct access using elementAt(5): " + s );
        outputBox.skipLine( 1 );
        
        enum = vector.elements( );
        
        outputBox.printLine("Scanning with nextElement:");
        
        while ( enum.hasMoreElements( ) ) {
            
            s = (String) enum.nextElement( );
            
            outputBox.printLine( "     " + s );
        }
        
        
        



    }
}