Class DeckOfCards
Class DeckOfCards
(Fig. E.9) 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 next Card
to be dealt from the deck
array and a named constant NUMBER_OF_CARDS
(line 9) indicating the number of Card
s in the deck (52).
1 // Fig. E.9: DeckOfCards.java 2 // DeckOfCards class represents a deck of playing cards. 3 import java.util.Random; 4 5 public class DeckOfCards 6 { 7 private Card[] deck; // array of Card objects 8 private int currentCard; // index of next Card to be dealt (0-51) 9 private static ...
Get Android™ How to Program, Second 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.