
public class Talon {

	private Card talon[] = new Card[52] ;
	private int theLength ;

	private Card emptyCard = new Card() ;

	public Talon () {
		String value, suit ;
		theLength = 52 ;

		for ( int i = 0 ; i < theLength ; i++ ) {
			do {
				value = Card.randomValue() ;
				suit  = Card.randomSuit() ;
			} while ( cardExists( value, suit, i ) ) ;

			talon[i] = new Card( value, suit ) ;
		}
	}

	public boolean cardExists( String value, String suit, int i ) {
		boolean itExists = false ;
		for ( int j = 0 ; j < i ; j++ )
			itExists = itExists || ( ( talon[j].getValue().equals(value) ) && ( talon[j].getSuit().equals(suit) ) ) ;
		return itExists ;
	}



	public Card popCard () {
		if ( theLength > 0 )
			return talon[--theLength] ;
		else
			return emptyCard ;
	}

	public int getLength () {
		return theLength ;
	}

	public Card cardAt( int i ) {
		if ( ( 0 <= i ) && ( i < theLength ) )
			return talon[i] ;
		else
			return emptyCard ;
	}

	public boolean isEmpty() {
		if ( theLength > 0 )
			return false ;
		else
			return true ;
	}

}

