Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8917921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:36:58+00:00 2026-06-15T05:36:58+00:00

I’m trying to solve a problem where I try to reset my deck of

  • 0

I’m trying to solve a problem where I try to reset my deck of cards once I’ve draw all cards. When I reach the end of the deck I should indeed get message Deck is empty! You must recreate and reshuffle deck of cards! but once deck has been recreated and re-shuffled it still keeps showing up this message.

So I am passing Card object to Deck class where is stored in array in stack fashion.

Why am I getting such output where I do indeed reset the deck of cards?

deal, bet, hit, stay, split, leave: deal

Drawing Player's card... 9 ♥
Drawing Dealer's card... A ♣
Drawing Player's card... 7 ♦
Drawing Dealer's card... K ♦

Dealers Hand: K_♦ A_♣ = 21
Players Hand: 7_♦ 9_♥ = 16

Dealer has BLACKJACK!

deal, bet, hit, stay, split, leave: deal

Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... 7 ♥
Drawing Dealer's card... 5 ♥
Drawing Player's card... K ♠
Drawing Dealer's card... 6 ♦

Dealers Hand: 6_♦ 5_♥ = 11
Players Hand: K_♠ 7_♥ = 17

deal, bet, hit, stay, split, leave: deal

Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... Q ♦
Drawing Dealer's card... 9 ♥
Drawing Player's card... 8 ♥
Drawing Dealer's card... 10 ♠

Dealers Hand: 10_♠ 9_♥ = 19
Players Hand: 8_♥ Q_♦ = 18

deal, bet, hit, stay, split, leave: deal

Deck is empty! You must recreate and reshuffle deck of cards!
Creating deck...
Shuffling deck...
Drawing Player's card... 3 ♣
Drawing Dealer's card... 6 ♠
Drawing Player's card... 4 ♠
Drawing Dealer's card... K ♠

Dealers Hand: K_♠ 6_♠ = 16
Players Hand: 4_♠ 3_♣ = 7

deal, bet, hit, stay, split, leave:

This is how I reset my deck of cards:

private static Deck createDeck(Deck deck)
{
    System.out.println("Creating deck...");
    deck = new Deck(DECKSIZE);
    deck.createDeck();

    System.out.println("Shuffling deck...");
    deck.shuffleDeck();

    return deck;
}

This is how I check if deck is empty or not:

private static Deck checkDeck(Deck deck)
{
    if(deck == null)
        return createDeck(deck);
    if(deck.isEmpty())
    {
        deck = new Deck(DECKSIZE);
        System.out.print("Deck is empty! You must recreate and reshuffle deck of cards!\n");
        return createDeck(deck);
    }
    else
        return deck;
}

I check the deck every time before I draw a card:

public static void drawFromDeck(Deck deck, Hand hand)
{
    deck = checkDeck(deck);

    Card temp = new Card(deck.pop());
    System.out.println("Drawing " + hand.getName() + "'s card... " + temp.toString());
    hand.insert(temp);

    System.out.print("\n");
}

initialDraw()

private static void 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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T05:36:59+00:00Added an answer on June 15, 2026 at 5:36 am

    There are a couple of scoping issue (for the Deck variable).

    To summarize, this is the type of mistake:

    void createObj(MyObject objt)
    {
        objt = new MyObject(); //Local Scope
    }
    //Caller
    MyObject obj = null;
    createObj(obj); // <-- New object will be created only within the function, obj will remain unaffected.
    // obj is still null;
    

    I suggest these changes (wrt http://ideone.com/S4Yv3l) for getting the code to work, however, you can improve your code.

    i) Change the signature of createDeck.

        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;
        }
    

    ii) CheckDeck

        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;
        }
    

    iii) InitialDraw

    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;
    }
    

    iv) In Main :

    deck = initialDraw(deck, playersHand, dealersHand);
    

    I have suggested changes only for one set of things, you can use the same principle to organize the other functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I've tracked down a weird MySQL problem to the two different ways I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.