DeckOfCards Method dealCard
Method dealCard
(lines 49–56) deals one Card
in the array. Recall that currentCard
indicates the index of the next Card
to be dealt (i.e., the Card
at the top of the deck). Thus, line 52 compares currentCard
to the length of the deck
array. If the deck
is not empty (i.e., currentCard
is less than 52), line 53 returns the “top” Card
and postincrements currentCard
to prepare for the next call to dealCard
—otherwise, null
is returned. Recall from Chapter 3 that null
represents a “reference to nothing.”
Get Java™ How To Program (Early Objects), Tenth 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.