... Card dealCard() { 45         // determine whether Cards remain to be dealt
46         if (currentCard < deck.length) {
47            return deck[currentCard++]; // return current Card in array
48         }
49         else {
50            return null; // return null to indicate that all Cards were dealt
51         }
52      }
53   }

DeckOfCards class represents a deck of playing cards.

DeckOfCards Constructor

The class’s constructor uses a for statement (lines 20–23) to fill the deck instance variable with Card objects. 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 through 51 (the deck array’s indices). Each Card is instantiated and initialized with two Strings—one from the faces array (which contains the String ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.