Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After </p> <pre><code>Deck test = new Deck(new Card[52]); </code></pre> <p>You never called createDeck(). Your constructor and createDeck are somewhat schizophrenic, by the way. You pass the deck into the constructor but you have no way to create a blank deck without creating a new array.</p> <p><em>edit</em></p> <ol> <li><p>Regarding the schizophrenia...</p> <p>For Deck's constructor, you have this:</p> <p>public Deck(Card[] card){ this.cards=card; }</p> <p>What's strange is that I see a Deck as a collection of cards, yet you pass the cards into the Deck. This may be just a matter of style. However, I'd sooner expect:</p> <p>public Deck() { createDeck(); }</p></li> <li><p>createDeck() has a weirdness, by the way - it is supposed to return an <code>int</code> but has no return statement. Perhaps a 'void' return in the signature would be better. And I'd make it private. If someone wants a new Deck, they should literally use <code>Deck deck = new Deck();</code>, not call <code>createDeck();</code></p></li> <li><p>I would never let Deck return the Cards[] array to the user. The data structure and other internals within Deck are nobody's business. <code>resetDeck()</code> does that. Not returning Card[] implies that Deck would have to provide methods such as <code>Card getTopCard()</code> or <code>Card getRandomCard()</code> since it no longer 'opens the kimono'. But that's a good thing - we want the Deck (a very nice noun) to have verb-ish methods that allow one to manipulate the deck.</p></li> <li><p>I see a non-standard loop construct: <code>for (int b=0; b&lt;=12; b++)</code> This is <em>not</em> wrong. However, generally speaking the conditional part of the loop is written without the &lt;=. Instead, a &lt; is used. So I'd expect <code>for(int b=0; b&lt;13; b++)</code> That being said, I ignore this semi-standard when the loop doesn't begin with zero.</p></li> <li><p>In Card, I see <code>public String getCardName()</code>. consider a slightly different implementation. The point is to remove lines of code (and hence bugs) by defining data structures instead of by writing explicit code. See how the stringy switch statement is gone, having been replaced by a single line of <em>run-time</em> code. The String array of cardNames is new but it's compile-time code and is unlikely to introduce an error.</p></li> </ol> <blockquote> <pre><code>public class Card { ... private static final String[] cardName = new String[] {'ONE','TWO','THREE', ...etc}; ... public String getCardName() { return cardName[cardFlippedNum]; } } </code></pre> </blockquote>
    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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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