Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of scoping issue (for the Deck variable). </p> <p>To summarize, this is the type of mistake:</p> <pre><code>void createObj(MyObject objt) { objt = new MyObject(); //Local Scope } //Caller MyObject obj = null; createObj(obj); // &lt;-- New object will be created only within the function, obj will remain unaffected. // obj is still null; </code></pre> <p>I suggest these changes (wrt <a href="http://ideone.com/S4Yv3l" rel="nofollow">http://ideone.com/S4Yv3l</a>) for getting the code to work, however, you can improve your code.</p> <p><strong>i)</strong> Change the signature of createDeck.</p> <pre><code> private static Deck createDeck() { System.out.println("Creating deck..."); Deck deck = new Deck(DECKSIZE); deck.createDeck(); System.out.println("Shuffling deck..."); deck.shuffleDeck(); return deck; } </code></pre> <p><strong>ii)</strong> CheckDeck</p> <pre><code> private static Deck checkDeck(Deck deck) { if(deck == null) return createDeck(); if(deck.isEmpty()) { System.out.print("Deck is empty! You must recreate and reshuffle deck of cards!\n"); return createDeck(); } return deck; } </code></pre> <p><strong>iii)</strong> InitialDraw</p> <pre><code>private static Deck initialDraw(Deck deck, Hand player, Hand dealer) { deck = checkDeck(deck); drawFromDeck(deck, player); // drawing players card deck = checkDeck(deck); drawFromDeck(deck, dealer); // drawing dealers card deck = checkDeck(deck); drawFromDeck(deck, player); // drawing players card deck = checkDeck(deck); drawFromDeck(deck, dealer); // drawing dealers card System.out.print("Dealers Hand:"); dealer.displayHand(); System.out.print(" = " + dealer.getHandTotal() + "\n"); System.out.print("Players Hand:"); player.displayHand(); System.out.print(" = " + player.getHandTotal() + "\n"); checkInitialDraw(player, dealer); return deck; } </code></pre> <p><strong>iv)</strong> In Main :</p> <pre><code>deck = initialDraw(deck, playersHand, dealersHand); </code></pre> <p>I have suggested changes only for one set of things, you can use the same principle to organize the other functions.</p>
    singulars
    1. This table or related slice is empty.
    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. 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