Class DeckOfCards

Class DeckOfCards (Fig. 7.10) declares as an instance variable a Card array named deck (line 7). An array of a reference type is declared like any other array. Class DeckOfCards also declares an integer instance variable currentCard (line 8) representing the sequence number (0–51) of the next Card to be dealt from the deck array, and a named constant NUMBER_OF_CARDS (line 9) indicating the number of Cards in the deck (52).

 1   // Fig. 7.10: DeckOfCards.java 2   // DeckOfCards class represents a deck of playing cards. 3   import java.security.SecureRandom; 4  5   public class DeckOfCards 6   { 7      private Card[] deck; // array of Card objects  8      private int currentCard; // index of next ...

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.