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

JAVA Define a Class Card that will store the face value of the Card and the Suit

ID: 3682281 • Letter: J

Question

JAVA

Define a Class Card that will store the face value of the Card and the Suit Value Include a minimun of 5 fields: Face Value as Integer Face Value as String Suit Value as Integer Suit Value as String o Card number of 1 to 52 (or 0 to 51) Include a method to return the value of both for printing. I suggest you use toString(). Create a class for the Deck of Cards containing a set of operations that do the following: Initializes a Linked List that contains all 52 cards in order. Draws one card at a time from the Deck and removes the card from the deck. Checks to see if there are any cards in the deck. Keeps track of how many cards are left in the deck. Shuffles the deck. Print the deck for debugging purposes as you test your game. Create a class for a dealt hand of cards containing a set of operations that do the following: Initializes an empty hand of cards. Prints the hand of cards. Keeps track of how many cards are in the hand. Draws a card from the deck and p

Explanation / Answer

public class DeckOfCards
   {
      public static final int NCARDS = 52;
  
      private Card[] deckOfCards;         // Contains all 52 cards
      private int currentCard;            // deal THIS card in deck    
  
      public DeckOfCards( )
      {
    deckOfCards = new Card[ NCARDS ];
  
    int i = 0;
  
    for ( int suit = Card.SPADE; suit <= Card.DIAMOND; suit++ )
         for ( int rank = 1; rank <= 13; rank++ )
        deckOfCards[i++] = new Card(suit, rank);
  
    currentCard = 0;         // Fresh deck of card...
      }
  
      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 += " ";
    }
    return ( s );
      }
   }