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

I need a Driver class for running the Deck Class. The output of the Driver and C

ID: 3834529 • Letter: I

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: 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 Deck ----------------------------------------------------------------

// represents the source of the cards for dealing

class Deck {

       private static final int MAX_PACKS = 6;

       private static final int NUM_CARDS_PER_PACK = 52;

       private static final int MAX_CARDS_PER_DECK = MAX_PACKS * NUM_CARDS_PER_PACK;

       private static Card[] masterPack;

       private Card[] cards;

       private int topCard;

       private int numPacks;

       // constructor

       public Deck(int numPacks) {

             this.numPacks = numPacks;

             masterPack = new Card[NUM_CARDS_PER_PACK];

             cards = new Card[(NUM_CARDS_PER_PACK * numPacks)];

             topCard = 0;

             allocateMasterPack();

             init(numPacks);

       }

       public boolean init(int numPacks) {

             topCard = 0;

             if (numPacks > this.numPacks) {

                    return false;

             } else {

                    for (int i = 0; i < (NUM_CARDS_PER_PACK * numPacks); i++) {

                          int present = i % NUM_CARDS_PER_PACK;

                          cards[i] = masterPack[present];

                    }

             }

             return true;

       }

       // mixes up the cards with the help of the standard random number generator

       public void shuffle() {

             for (int i = 0; i < 500; i++) {

                    int rand1 = (int) (Math.random() * (NUM_CARDS_PER_PACK * numPacks));

                    int rand2 = (int) (Math.random() * (NUM_CARDS_PER_PACK * numPacks));

                    Card temp = new Card(cards[rand1]);

                    cards[rand1] = cards[rand2];

                    cards[rand2] = temp;

             }

       }

       // returns and removes the card in the top occupied position of cards[]

       public Card dealCard() {

             Card top = new Card(cards[topCard]);

             topCard++;

             return top;

       }

       // An accessor for the int

       public int topCard() {

             return topCard;

       }

       // Accessor for an individual card

       public Card inspectCard(int k) {

             if (k >= topCard && k < (NUM_CARDS_PER_PACK * numPacks)) {

                    Card kcard = new Card(cards[k]);

                    return kcard;

             } else {

                    // error flag = true

                    return new Card('E', Card.Suit.spades); // error card, in rare

                    // cases;

             }

       }

       // this is a method that will be called by the constructor

       private static void allocateMasterPack() {

             for (int i = 0; i < NUM_CARDS_PER_PACK; i++) {

                    char val = 'A';

                    if (i % 13 == 0) {

                          val = 'A';

                    } else if ((i % 13) >= 1 && (i % 13) <= 8) {

                          String temp = ((i % 13) + 1) + "";

                          val = temp.charAt(0);

                    } else if ((i % 13) == 9) {

                          val = 'T';

                    } else if ((i % 13) == 10) {

                          val = 'J';

                    } else if ((i % 13) == 11) {

                          val = 'Q';

                    } else if ((i % 13) == 12) {

                          val = 'K';

                    }

                    if (i < 13) {

                          masterPack[i] = new Card(val, Card.Suit.spades);

                    } else if (i >= 13 && i < 26) {

                          masterPack[i] = new Card(val, Card.Suit.hearts);

                    } else if (i >= 26 && i < 39) {

                          masterPack[i] = new Card(val, Card.Suit.diamonds);

                    } else if (i >= 39 && i < 52) {

                          masterPack[i] = new Card(val, Card.Suit.clubs);

                    }

             }

       }

}/* ---------------------------------------------------------

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

Explanation / Answer

So we have deck class already, we need to implement card class and driver class which will call the methods in deck class.

firstly we will make card class:

Now we workout DRIVER class:

class Driver {

  public static void main(String... args) {

    // Ask for number of players.

    // Ask for cards per hand.

    // Create a deck.

    // Deal the given amount of hands with the given size.

  }

}

I have commented in driver class which will provide you the understanding about what to call.

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