Quick solution:
private static Deck initialDraw(Deck deck, Hand player, Hand dealer)
{
deck = drawFromDeck(deck, player);
deck = drawFromDeck(deck, dealer);
deck = drawFromDeck(deck, player);
deck = drawFromDeck(deck, dealer);
System.out.print("\n");
showHands(player, dealer);
compareHands(player, dealer);
return deck;
}
Explanation:
Inside drawFromDeck
you are creating/updating the deck and returning this, but not updating the variable as seen in initialDraw
. This may not be such an issue (since Objects are passed by reference, but test before relying on it!), but I assume you are passing null
into initialDraw
, and so null
is being passed to each drawFromDeck
call, and so a new Deck
is created each time.
For your Edit where you code works
In that case, you are ensuring that deck
is not a null
reference, but a reference to an actual Deck
object, and so you will be passing a reference to a Deck
object to each drawFromDeck
call, rather than passing a null
reference each time.