if(NUMBER_IN_DECK[card.getValue()] == countOf(card))
throw new IllegalStateException("Cannot add more cards of value " +
card.getValue());
cards.add(card);
}
public Card top()
{
if(isEmpty())
throw new IllegalStateException("Cannot call top on an empty deck");
return (Card) cards.get(0);
}
…
private int countOf(Card card)
{
int result = 0;
for(Iterator i = cards.iterator(); i.hasNext(); )
{
Card each = (Card) i.next();
if(each.getValue() == card.getValue())
result++;
}
return result;
}
}
public class Hand
{
…
文章來源于領測軟件測試網 http://www.kjueaiud.com/