next up previous
Next: Shuffle the deck Up: Assignment 10: Cards and Previous: Compare cards

Make a deck

1.
Write a static method called newDeck that creates an array of 52 Cards and that fills the array with 52 new Cards. For now, you should make all the cards identical, like a trick deck that only has Aces of Spades. You should use new once to create the array, and 52 times (inside a loop) to create each of the cards.
2.
Write a static method called printDeck that takes an array of cards and prints the cards in the deck in order. Your code should not assume that the deck has 52 cards; instead, use the length field of the array object to determine the number of cards.

3.
Now modify newDeck so that instead of 52 identical cards, the deck contains exactly one of each card.



Allen B. Downey
4/21/1998