February 2014
Beginner
1248 pages
62h 25m
English
Figure 7.11 demonstrates class DeckOfCards. Line 9 creates a DeckOfCards object named myDeckOfCards. The DeckOfCards constructor creates the deck with the 52 Card objects in order by suit and face. Line 10 invokes myDeckOfCards’s shuffle method to rearrange the Card objects. Lines 13–20 deal all 52 Cards and print them in four columns of 13 Cards each. Line 16 deals one Card object by invoking myDeckOfCards’s dealCard method, then displays the Card left justified in a field of 19 characters. When a Card is output as a String, the Card’s toString method (lines 17–20 of Fig. 7.9) is implicitly invoked. Lines 18–19 start a new line after every four Cards.
Read now
Unlock full access