QuestionQuestion

Main topics: Programmer defined methods
Random number generators
Arrays

Program Specification:
You are to develop a program which emulates a full deck of playing cards. That is 4 suits (Clubs, Spades, Hearts, and Diamonds) and 13 ranks (Ace, 2, 3, 4, 5, 6, 7, 8, 9, Jack, Queen, King) in each suit. This of course makes for a total of 52 playing cards in the deck.
Mandatory methods:

public static void initDeck(boolean[] deck)
// set the values of deck to indicate that they are all
// present - not dealt yet.

public static boolean emptyDeck(boolean[] deck)
// returns whether or not all the cards in the deck
// have already been dealt.

public static int dealCard(boolean[] deck)
// returns a card (an int in the range 0 to 51) at random
// that has not been dealt since the deck was initialize
// via intDeck. Also notes (in deck) that this card is
// no longer available.

public static void printCard(int card)
// given a card (an int in the range 0 to 51) prints
// an appropriate representation of this card based
// on a 1-1 and onto mapping of the set [0, 51] to
// the cards described above.

Rules and Requirements:
- Your main method must end with the following block of code, which cannot be modified.

boolean[] myDeck = new boolean[52];

final int cardsPerRow = 8;
int cardsThisRow = 0;
int myCard;
initDeck(myDeck);
System.out.println("\nHere is a shuffled deck ...\n");
while (!emptyDeck(myDeck))
{
    myCard = dealCard(myDeck);
    ++cardsThisRow;
      if (cardsThisRow <= cardsPerRow)
{
    printCard(myCard);
    System.out.print(" ");
}
else
{
    System.out.println("");
    cardsThisRow = 1;
    printCard(myCard);
    System.out.print(" ");
}
}
System.out .println('\n');

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

public class DeckOfCards {

    public static void initDeck(boolean[] deck)
    // set the values of deck to indicate that they are all
    // present - not dealt yet.
    {
       for (int i = 0; i < deck.length; i++) {
            deck[i] = true;
       }
    }

    public static boolean emptyDeck(boolean[] deck)
    // returns whether or not all the cards in the deck
    // have already been dealt.
    {
       for (boolean card: deck) {
            if (card)
                return false;
       }
       return true;
    }

    public static int dealCard(boolean[] deck)
    // returns a card (an int in the range 0 to 51) at random
    // that has not been dealt since the deck was initialize
    // via intDeck. Also notes (in deck) that this card is
    // no longer available.
    {
       if (emptyDeck...

By purchasing this solution you'll be able to access the following files:
Solution.java.

50% discount

Hours
Minutes
Seconds
$45.00 $22.50
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats