You'll want to store the whole collection of
cards in an array or Collection object. Since you know there are exactly 52
cards and the number is fixed, an array would be just fine. So the class might look like
class Deck {
public static final int NUMBER_OF_CARDS=52;
private Card m_cards;
public Deck() {
m_cards = new Card[NUMBER_OF_CARDS];
for (int i=0; i<NUMBER_OF_CARDS; ++i) {
m_cards[i] = new Card(i+1);
}
}
}
[/code]
Now the "method" in Card is actually a Constructor, and Constructors don't have a return type, not even void, and they can't be static; so that class looks like
[code]
class Card {
private int m_number;
public Card(int number) {
m_number = number;
}
}
[/code]
Now, as far as "subdecks" go, I'm not a Cribbage player so I'll just have to take your
word for it. I'd simply create a new Deck constructor that took an array of Card objects to include, and copied them into a new array stored in the m_cards member; so to create a subdeck, you'd create Deck by specifying only the cards it should contain. If a Deck should know about its subdecks, then Deck should have a java.util.Set or other collection of Deck children.