So far, this chapter’s examples have used arrays of value-type elements. This section uses random-number generation and an array of reference-type elements—namely, objects representing playing cards—to develop a class that simulates card shuffling and dealing. This class can then be used to implement apps that play card games. The exercises at the end of the chapter use the techniques developed here to build a poker app.
We first develop class
Card (Fig. 8.9), which represents a playing card that has a face (e.g.,
"King") and a suit (e.g.,
"Spades"). Next, we develop class
DeckOfCards (Fig. 8.10), which creates a ...