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
{
…
文章来源于领测软件测试网 https://www.ltesting.net/