Note that there are some explanatory texts on larger screens.

plurals
  1. POCard Deck Using ENUM, and Boolean Array to create the Deck. Java
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/10592817/how-to-create-a-deck-of-cards-constructor">how to create a deck of cards constructor</a> </p> </blockquote> <p>Im trying to create a "deck of cards" using <code>enums</code>. I already have my enum declared, but I'm stuck in how exactly to create the deck of cards using a boolean array. </p> <p>So far I tried to initialize my constructor, but I don't know what direction to take now. Any help would be greatly appreciated it. </p> <pre><code>package Cards; //Class to represent a standard Deck of 52 Playing-Cards // The following functionality is provided // Default Constructor - creates a complete deck of cards // shuffle() - collects all 52 cards into the deck // deal() - returns a randomly selected card from the deck // import java.util.Random; public class DeckOfCards { public static final int DECK_SIZE = 52; // Instance Variables private boolean[] deck; // An implicit set of 52 Playing-Cards private int cardsInDeck;// Number of cards currently in the deck private Random dealer; // Used to randomly select a card to be dealt // Constructor public DeckOfCards() { deck = new boolean[DECK_SIZE]; for (PlayingCard.CardSuit suit : PlayingCard.CardSuit.values()) for (PlayingCard.CardRank rank : PlayingCard.CardRank.values()) deck[cardsInDeck++] = true; } // Collect all 52 Playing-Cards into the deck public void shuffle() { } // Simulate dealing a randomly selected card from the deck // Dealing from an empty deck results in a RuntimeException public PlayingCard deal() { return null; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload