SQL

Friday, 14 August 2015

Case Study: Card Shuffling and Dealing Simulation


The elements of an array can be either primitive types or reference types. This example 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 applications that play specific card games. 

I first develop class Card , which represents a playing card that has a face
(e.g., "Ace", "Deuce", "Three", …, "Jack", "Queen", "King") and a suit (e.g., "Hearts", "Diamonds", "Clubs", "Spades"). Next, I develop the DeckOfCards class, which creates a deck of 52 playing cards in which each element is a Card object. I then build a test application that demonstrates class DeckOfCards’s card shuffling and dealing capabilities.





Output:

Jack of Clubs      Nine of Hearts     Jack of Hearts     Nine of Diamond  
Six of Clubs       Seven of Diamond   Queen of Diamond   Eight of Spades  
Queen of Clubs     Ace of Hearts      Five of Clubs      King of Hearts    
Eight of Clubs     Eight of Diamond   Ten of Diamond     King of Clubs    
Jack of Diamond    Queen of Spades    Four of Clubs      Five of Hearts    
Jack of Spades     Seven of Hearts    Three of Clubs     Four of Spades    
Ace of Clubs       Five of Spades     Ten of Clubs       Ace of Spades    
King of Spades     Six of Diamond     King of Diamond    Nine of Clubs    
Deuce of Spades    Six of Hearts      Six of Spades      Ten of Spades    
Deuce of Diamond   Queen of Hearts    Three of Diamond   Deuce of Clubs    
Three of Spades    Seven of Spades    Four of Diamond    Three of Hearts  
Seven of Clubs     Ten of Hearts      Five of Diamond    Eight of Hearts  
Ace of Diamond     Four of Hearts     Deuce of Hearts    Nine of Spades    

Post a Comment