public class ArrayList<E> {

    private Object[] myArray;
    private final int INIT_SIZE =10;
    private int count;
    
    public ArrayList()
    {
        myArray = new Object[INIT_SIZE];
        count = 0;
    }
    
    public int size()
    {
        return count;
    }
    public boolean isEmpty()
    {
        return count == 0;
    }
    
    private boolean checkBounds( int r, int size )
    {
        if ( r < 0 || r >= size )
            throw new BoundaryViolationException();
        return true;
    }
    
    public E elementAtRank( int r ) throws BoundaryViolationException
    {
        checkBounds( r, count );
        return (E)myArray[ r ];
    }
    public E replaceAtRank( int r, E e) throws BoundaryViolationException
    {
        return null;
    }
    public void insertAtRank( int r, E e ) throws BoundaryViolationException
    {
        checkBounds( r, count+1 );
        if ( count == myArray.length )
            resize();
        for ( int i = count; i >= r+1; i-- )
            myArray[i] = myArray[i-1];
        myArray[r] = e;
        count++;
            
    }
    
    private void resize()
    {
        Object[] myNewArray = new Object[myArray.length * 2];
        for ( int i = 0; i < myArray.length; i++ )
            myNewArray[i] = myArray[i];
        myArray = myNewArray;
    }
        
    public E removeAtRank( int r ) throws BoundaryViolationException
    {
        return null;
    }
}