I'm trying to create a deck of cards with two variations: one which can choose and return a card from a standard 52 deck of cards with no cards repeating. And then another "infinite" deck of cards in which its okay to repeat cards.
public Deck(int a) {
if (a == 0) {
deckOf52();
} else {
infiniteDeck();
}
}
public void deckOf52() {
}
public void infiniteDeck() {
cards = new ArrayList<Card>(52);
for (int a = 0; a <= 3; a++) {
for (int b = 0; b <= 12; b++) {
cards.add(new Card(a, b));
}
}
}
public Card getCard() {
Random generator = new Random();
int index = generator.nextInt(cards.size());
return cards.remove(index);
}
The infiniteDeck can do exactly as I need, but I'm unsure of how to get the deckOf52 method to do the same and be restricted solely to the 52 cards with none repeating.
Does anyone have any ideas or anything to point me in the right direction?
Each card in infinite deck is unique and getCard removes each card it uses, so each card will only ever appear once.
I am not sure what you are trying to do but this will satisfy the description you have given us.