Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help WIth The Hand Class And Driver. Java Program public class DeckOfCards

ID: 3684455 • Letter: N

Question

Need Help WIth The Hand Class And Driver. Java Program

public class DeckOfCards
   {
private Card c1;
private Card c2;
...
private Card c52;
// 52 Card variables !!!
   }
public class DeckOfCards
   {
public static final int NCARDS = 52;

private Card[] deckOfCards; // Contains all 52 cards

   /* ---------------------------------------------------
   The constructor method: make 52 cards in a deck
   --------------------------------------------------- */
public DeckOfCards( )
{
   /* =================================================================
First: create the array
================================================================= */
   deckOfCards = new Card[ NCARDS ]; // Very important !!!
   // We must crate the array first !

   /* =================================================================
   Next: initialize all 52 card objects in the newly created array
================================================================= */
   int i = 0;

   for ( int suit = Card.DIAMOND; suit <= Card.SPADE; suit++ )
for ( int rank = 1; rank <= 13; rank++ )
deckOfCards[i++] = new Card(suit, rank); // Put card in
// position i
}
}
public String toString()
   {
String s = "";
int k;

k = 0;
for ( int i = 0; i < 4; i++ )
{
   for ( int j = 1; j <= 13; j++ )
   s += ( deckOfCards[k++] + " " );

   s += " "; // Add NEWLINE after 13 cards
}
return ( s );
   }



// This class represents one playing card.
public class Card
{
// Card suits (provided for your convenience - use is optional)
public static final int SPADES = 0;
public static final int HEARTS = 1;
   public static final int CLUBS = 2;
public static final int DIAMONDS = 3;

// Card faces (provided for your convenience - use is optional)
public static final int ACE = 1;
public static final int TWO = 2;
public static final int THREE = 3;
public static final int FOUR = 4;
public static final int FIVE = 5;
public static final int SIX = 6;
public static final int SEVEN = 7;
public static final int EIGHT = 8;
public static final int NINE = 9;
public static final int TEN = 10;
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;

//define fields.
private int suit;
   private int face;
private boolean faceup;


// This constructor builds a card with the given suit and face, turned face down.
public Card(int cardSuit, int cardFace)
{
this.suit = cardSuit;
this.face = cardFace;
this.faceup = false;
}

// This method retrieves the suit (spades, hearts, etc.) of this card.
public int getSuit()
{
return this.suit;
}

// This method retrieves the face (ace through king) of this card.
public int getFace()
{
return this.face;
}

// This method retrieves the numerical value of this card
// (usually same as card face, except 1 for ace and 10 for jack/queen/king)
public int getValue()
{
int value;

if( this.face >= 10 )
value = 10;
else
value = this.face;


return value; // replace this line with your code
}

// This method determines whether the front of the card should be visible.
public boolean isFaceUp()
{
return this.faceup;
}

// This method records that the front of the card should be visible.
public void turnFaceUp()
{
this.faceup = true;
}

// This method records that only the back of the card should be visible.
public void turnFaceDown()
{
this.faceup = false;
}


public String toString(){
String cardname = "";

String suitname = "";
if(this.suit == 0)
suitname = "Spades";
if(this.suit ==1)
suitname = "Hearts";
if(this.suit ==2)
suitname = "Clubs";
if(this.suit ==3)
suitname = "Diamonds";

if(this.face == 1 || this.face > 10){
String facename = "";
if(this.face == 1)
   facename = "Ace";
if(this.face == 11)
facename = "Jack";
if(this.face == 12)
facename = "Queen";
if(this.face == 13)
facename = "King";

cardname = facename + " of " + suitname;
}

else if(this.face != 1 && this.face <= 10)
cardname = this.face + " of " + suitname;



return cardname;
}
}

1. Define a Class Card that will store the face value of the Card and the Suit Value 1. Include a minimun of 5 fields: o Face Value as Integer o Face Value as String o Suit Value as Integer o Suit Value as String o Card number of 1 to 52 (or 0 to 51) 2. Include a method to return the value of both for printing. I suggest you use toString). 2. Create a class for the Deck of Cards containing a set of operations that do the following: 1. Initializes a Linked List that contains all 52 cards in order. 2. Draws one card at a time from the Deck and removes the card from the deck. 3. Checks to see if there are any cards in the deck. 4. Keeps track of how many cards are left in the deck 5. Shuffles the deck 6. Print the deck for debugging purposes as vou test vour game. 3. Create a class for a dealt hand of cards containing a set of operations that do the following: 1. Initializes an empty hand of cards. 2. Prints the hand of cards. 3. Keeps track of how many cards are in the hand 4. Draws a card from the deck and places it in the hand 5. Removes the card from the hand randomly. 6. Removes the card from the hand by position 4. Create a Driver program that tests each of the methods for the deck and for the hand. Get one component working before moving on to the next 1. Print out the deck of cards 2. Print outthe dealt hand. 3. Prints out how many cards are in the deck 4. Prints out how many cards are in the hand. 5. Removes a card from the deck and places it in the hand a. Don't let a card be removed if the deck is empty a. Don't let a card be removed if the hand is empty. a. Don't let a card be removed if the hand is empty. 5. You must use Referenced-based Linked Lists for this progranm 6. Removes a card from the hand by position. f. Removes a card from the hand randomly. 6. You cannot use any built-in Java methods to manipulate your Linked Lists - you must write your own Linked List operations

Explanation / Answer

public class DeckOfCards
   {
private Card c1;
private Card c2;
...
private Card c52;
// 52 Card variables !!!
   }
public class DeckOfCards
   {
public static final int NCARDS = 52;

private Card[] deckOfCards; // Contains all 52 cards

   /* ---------------------------------------------------
   The constructor method: make 52 cards in a deck
   --------------------------------------------------- */
public DeckOfCards( )
{
   /* =================================================================
First: create the array
================================================================= */
   deckOfCards = new Card[ NCARDS ]; // Very important !!!
   // We must crate the array first !

   /* =================================================================
   Next: initialize all 52 card objects in the newly created array
================================================================= */
   int i = 0;

   for ( int suit = Card.DIAMOND; suit <= Card.SPADE; suit++ )
for ( int rank = 1; rank <= 13; rank++ )
deckOfCards[i++] = new Card(suit, rank); // Put card in
// position i
}
}
public String toString()
   {
String s = "";
int k;

k = 0;
for ( int i = 0; i < 4; i++ )
{
   for ( int j = 1; j <= 13; j++ )
   s += ( deckOfCards[k++] + " " );

   s += " "; // Add NEWLINE after 13 cards
}
return ( s );
   }



// This class represents one playing card.
public class Card
{
// Card suits (provided for your convenience - use is optional)
public static final int SPADES = 0;
public static final int HEARTS = 1;
   public static final int CLUBS = 2;
public static final int DIAMONDS = 3;

// Card faces (provided for your convenience - use is optional)
public static final int ACE = 1;
public static final int TWO = 2;
public static final int THREE = 3;
public static final int FOUR = 4;
public static final int FIVE = 5;
public static final int SIX = 6;
public static final int SEVEN = 7;
public static final int EIGHT = 8;
public static final int NINE = 9;
public static final int TEN = 10;
public static final int JACK = 11;
public static final int QUEEN = 12;
public static final int KING = 13;

//define fields.
private int suit;
   private int face;
private boolean faceup;


// This constructor builds a card with the given suit and face, turned face down.
public Card(int cardSuit, int cardFace)
{

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote