Question: I need a Driver class for running the Deck Class. The output of the Driver and Codes for the Deck Class are given. Deck :
I need a Driver class for running the Deck Class. The output of the Driver and Codes for the Deck Class are given.
Deck: A class that represents the source of the cards for dealing and, as the game progresses, the place from which players can receive new cards (say, as they pick cards "from the deck" or when future hands are to be dealt from the same deck). Recall this picture, which relates the Deck to the various Hands that it creates through the process called "dealing":

Let's deconstruct the meaning of this important class.
y the operating system, is a resource we do not abuse).
Example Test Run of Card Class
//Deck Class:
class Card
{
// type and constants
public enum Suit { clubs, diamonds, hearts, spades }
static char DEFAULT_VAL = 'A';
static Suit DEFAULT_SUIT = Suit.spades;
// private data
private char value;
private Suit suit;
boolean errorFlag;
// 4 overloaded constructors
public Card(char value, Suit suit)
{ // because mutator sets errorFlag, we don't have to test
set(value, suit);
}
public Card(char value)
{
this(value, Suit.spades);
}
public Card()
{
this(DEFAULT_VAL, DEFAULT_SUIT);
}
// copy constructor
public Card(Card card)
{
this(card.value, card.suit);
}
// mutators
public boolean set(char value, Suit suit)
{
char upVal; // for upcasing char
// convert to uppercase to simplify
upVal = Character.toUpperCase(value);
if ( !isValid(upVal, suit))
{
errorFlag = true;
return false;
}
// else implied
errorFlag = false;
this.value = upVal;
this.suit = suit;
return true;
}
// accessors
public char getVal()
{
return value;
}
public Suit getSuit()
{
return suit;
}
public boolean getErrorFlag()
{
return errorFlag;
}
// stringizer
public String toString()
{
String retVal;
if (errorFlag)
return "** illegal **";
// else implied
retVal = String.valueOf(value);
retVal += " of ";
retVal += String.valueOf(suit);
return retVal;
}
// helper
private static boolean isValid(char value, Suit suit)
{
// don't need to test suit (enum), but leave in for clarity
char upVal; // string to hold the 1-char value
String legalVals = "23456789TJQKA";
// convert to uppercase to simplify (need #include )
upVal = Character.toUpperCase(value);
// check for validity
if ( legalVals.indexOf(upVal) >= 0 )
return true;
else
return false;
}
public boolean equals(Card card)
{
if (this.value != card.value)
return false;
if (this.suit != card.suit)
return false;
if (this.errorFlag != card.errorFlag)
return false;
return true;
}
}
/* --------------------------Driver Run Test-------------------------------
A of spades / K of spades / Q of spades / J of spades / T of spades / 9 of spades / 8 of spades / 7 of spades / 6 of spades / 5 of spades / 4 of spade s / 3 of spades / 2 of spades / A of hearts / K of hearts / Q of hearts / J of hearts / T of hearts / 9 of hearts / 8 of hearts / 7 of hearts / 6 of hearts / 5 of hearts / 4 of hearts / 3 of hearts / 2 of hearts / A of diamo nds / K of diamonds / Q of diamonds / J of diamonds / T of diamonds / 9 of diamonds / 8 of diamonds / 7 of diamonds / 6 of diamonds / 5 of diamonds / 4 of diamonds / 3 of diamonds / 2 of diamonds / A of clubs / K of clubs / Q of clubs / J of clubs / T of clubs / 9 of clubs / 8 of clubs / 7 of clubs / 6 of clubs / 5 of clubs / 4 of clubs / 3 of clubs / 2 of clubs / K of spades / 9 of clubs / Q of hearts / T of diamonds / 9 of spades / 5 of hear ts / 2 of clubs / A of hearts / J of hearts / K of clubs / T of hearts / 4 of sp ades / 7 of hearts / 3 of spades / Q of spades / A of clubs / 8 of spades / 5 of clubs / T of clubs / J of spades / 2 of spades / 6 of diamonds / 2 of diamonds / 8 of diamonds / 4 of hearts / 2 of hearts / 6 of hearts / 5 of spades / 8 of h earts / 7 of diamonds / 7 of spades / Q of diamonds / K of hearts / J of diamond s / T of spades / 8 of clubs / 3 of diamonds / J of clubs / 6 of spades / 4 of c lubs / K of diamonds / 4 of diamonds / 3 of clubs / A of spades / 9 of hearts / Q of clubs / A of diamonds / 6 of clubs / 5 of diamonds / 7 of clubs / 3 of hear ts / 9 of diamonds / A of spades / K of spades / Q of spades / J of spades / T of spades / 9 of spades / 8 of spades / 7 of spades / 6 of spades / 5 of spades / 4 of spade s / 3 of spades / 2 of spades / A of hearts / K of hearts / Q of hearts / J of hearts / T of hearts / 9 of hearts / 8 of hearts / 7 of hearts / 6 of hearts / 5 of hearts / 4 of hearts / 3 of hearts / 2 of hearts / A of diamo nds / K of diamonds / Q of diamonds / J of diamonds / T of diamonds / 9 of diamonds / 8 of diamonds / 7 of diamonds / 6 of diamonds / 5 of diamonds / 4 of diamonds / 3 of diamonds / 2 of diamonds / A of clubs / K of clubs / Q of clubs / J of clubs / T of clubs / 9 of clubs / 8 of clubs / 7 of clubs / 6 of clubs / 5 of clubs / 4 of clubs / 3 of clubs / 2 of clubs / A of sp ades / K of spades / Q of spades / J of spades / T of spades / 9 of spades / 8 of spades / 7 of spades / 6 of spades / 5 of spades / 4 of spades / 3 of spades / 2 of spades / A of hearts / K of hearts / Q of hearts / J of he arts / T of hearts / 9 of hearts / 8 of hearts / 7 of hearts / 6 of hearts / 5 of hearts / 4 of hearts / 3 of hearts / 2 of hearts / A of diamonds / K of diamonds / Q of diamonds / J of diamonds / T of diamonds / 9 of diamond s / 8 of diamonds / 7 of diamonds / 6 of diamonds / 5 of diamonds / 4 of di amonds / 3 of diamonds / 2 of diamonds / A of clubs / K of clubs / Q of clu bs / J of clubs / T of clubs / 9 of clubs / 8 of clubs / 7 of clubs / 6 of clubs / 5 of clubs / 4 of clubs / 3 of clubs / 2 of clubs / 6 of diamonds / 7 of clubs / 9 of hearts / 4 of diamonds / 9 of diamonds / J of hearts / 3 of spades / 2 of clubs / J of clubs / A of hearts / J of cl ubs / Q of hearts / Q of diamonds / 7 of clubs / 2 of diamonds / 5 of clubs / K of spades / 5 of clubs / 5 of diamonds / 8 of hearts / 3 of clubs / 6 of hearts / A of spades / A of hearts / 4 of hearts / J of diamonds / A of clubs / 3 of diamonds / A of diamonds / K of diamonds / 6 of clubs / 4 of spades / 6 of hearts / 7 of spades / K of clubs / 3 of hearts / 3 of hearts / K of spades / Q of spades / J of spades / 7 of hearts / J of hearts / K of hearts / T of spades / K of clubs / 8 of hearts / 2 of spades / A of di amonds / 4 of diamonds / Q of clubs / T of diamonds / 7 of hearts / 9 of cl ubs / T of clubs / 7 of spades / 6 of spades / 6 of spades / K of diamonds / Q of spades / 7 of diamonds / Q of hearts / J of spades / 3 of clubs / 5 of hearts / K of hearts / 9 of spades / 9 of clubs / 2 of clubs / 7 of dia monds / 8 of diamonds / T of spades / 8 of clubs / 8 of diamonds / 8 of clu bs / T of diamonds / 4 of spades / 9 of hearts / A of spades / 8 of spades / 4 of hearts / T of hearts / 5 of diamonds / T of hearts / 5 of spades / 9 of diamonds / 5 of hearts / T of clubs / Q of diamonds / 6 of diamonds / 3 of spades / J of diamonds / 8 of spades / Q of clubs / 2 of diamonds / 2 of hearts / 6 of clubs / 2 of hearts / 9 of spades / 4 of clubs / 2 of spad es / 3 of diamonds / 5 of spades / 4 of clubs / A of clubs / --------------------------------------------------------- */
--------------------------------------------------------------------------------------
hand
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
