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

Given these three classes of code: Class 1: Card /** * A class of playing cards.

ID: 3751942 • Letter: G

Question

Given these three classes of code:

Class 1: Card

/**

* A class of playing cards.

*/

public class Card

{

   private static final String[] SUIT_DESCRIPTION =

       {"Spades", "Hearts", "Diamonds", "Clubs"};

   private static final String[] FACE_VALUE_DESCRIPTION =

       { "Ace", "2", "3", "4", "5", "6", "7", "8", "9",

               "10", "Jack", "Queen", "King"};

   private int suit;

   private int faceValue;

  

   /**

   * Create a new card with a given suit and value

   *

   * @param v the face value of the card (0 - 12)

   * @param s the suit of the card (0 - 3)

   */

   public Card(int v, int s)

   {

       faceValue = v;

       suit = s;

   }

  

   /**

   * @return the suit of this card

   */

   public int getValue()

   {

       return faceValue;

   }

  

   /**

   * @see java.lang.Object#toString()

   */

   public String toString()

   {

       return FACE_VALUE_DESCRIPTION[faceValue] + " of " + SUIT_DESCRIPTION[suit];

   }

}

Class 2: Cardrunner

/**

* Just a main method to let us play with Decks

* and Cards

*/

public class CardRunner

{

  

   /**

   * Variables of the type Card are declared and cards are created as well

   * The deck of the cards is created and shuffled

   * @param args

   */

   public static void main(String[] args)

   {

       Card c1 = new Card (0,0);

       System.out.println(c1);

      

       Card c2 = new Card(12,3);

       System.out.println(c2);

      

       System.out.println();

       Deck d = new Deck();

       d.shuffle();

       System.out.println(d);

   }

}

Class 3: Deck

/**

* A standard deck of 52 cards in four suits.

*/

public class Deck

{

   private static final int NUMBER_OF_SUITS = 4;

   private static final int NUMBER_OF_CARDS = 52;

   Card[] cards;

  

   /**

   * Create the deck by filling it with the appropriate cards

   */

   public Deck()

   {

       cards = new Card[NUMBER_OF_CARDS];

       int position = 0;

       for (int suit = 0; suit < NUMBER_OF_SUITS; suit++)

       {

           for (int faceValue = 0;

                   faceValue < NUMBER_OF_CARDS/NUMBER_OF_SUITS;

                   faceValue++)

           {

               cards[position] =

                       new Card(faceValue, suit);

               position++;

           }

       }

   }

  

   /**

   * @see java.lang.Object#toString()

   */

   public String toString()

   {

       String s = new String();

       for (int i = 0; i < cards.length; i++)

       {

           s = s + cards[i] + " ";

       }

       return s;

   }

  

   /**

   * randomly shuffle the cards using the Fisher-Yates shuffle

   */

   public void shuffle()

   {

       for (int i = 0; i < NUMBER_OF_CARDS; i++)

       {

           int swapPosition = (int) (Math.random() * (NUMBER_OF_CARDS - i) + i);

           Card temp = cards[i];

           cards[i] = cards[swapPosition];

           cards[swapPosition] = temp;

       }

   }

}

Question:

Explain how this code works:

/**

* @see java.lang.Object#toString()

*/

Public String toString()

{

   return “faceValue = “ + faceValue + “ and suit = “

       + SUIT_DESCRIPTION[suit];

}

Explanation / Answer

Public String toString()

{

   return “faceValue = “ + faceValue + “ and suit = “

       + SUIT_DESCRIPTION[suit];

}

The above code will display each card description Ex: like facevalue = 8 and suit = club

________Thank You

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