DeckOfCards Constructor
The class’s constructor instantiates array deck (line 20) with NUMBER_OF_CARDS (52) elements that are all null by default. Lines 24–26 fill the deck with Cards. The loop initializes control variable count to 0 and loops while count is less than deck.length, causing count to take on each integer value from 0 to 51 (the indices of array deck). Each Card is instantiated and initialized with a String from the faces array (which contains "Ace" through "King") and a String from the suits array (which contains "Hearts", "Diamonds", "Clubs" and "Spades"). The calculation count % 13 always results in a value from 0 to 12 (the 13 indices of the faces array in lines 16–17), and the calculation count / 13 always results in a value ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access