1

How do I perform the perfectShuffle operation to my "deck" array?

I do not know how to import the "deck" array into my perfectShuffle method/class (idk wtf is the difference)

This Does NOT compile because my perfectShuffle cant find ''deck''

I'm pretty sure you're gonna look at my code and be like 'wtf do u even know what you're doing?' well no I dont know what i'm doing but ive gotten super far with not knowing what im doing by creating a deck array of every card in a deck of cards.

Im struggling to find the flow from class/method/object/instance watever and how they interact.

Any help or points to resources is greatly appreciated.

public String[] Deck(){
    String[] deck = new String[52];

    //Populate Deck 2-10
    for (int i=0; i<52; i++){
        if (i<9){
            for (int j=2; j<=10; j++){
                deck[i]=(j+" of Clubs");
                i++;
            }
        }
        if (12<i&&i<22){
            for (int j=2; j<=10; j++){
                deck[i]=(j+" of Diamonds");
                i++;
            }
        }
        if (25<i&&i<35){
            for (int j=2; j<=10; j++){
                deck[i]=(j+" of Hearts");
                i++;
            }
        }
        if (38<i&&i<48){
            for (int j=2; j<=10; j++){
                deck[i]=(j+" of Spades");
                i++;
            }
        }
        else {
            deck[9]=("Jack of Clubs");
            deck[10]=("Queen of Clubs");
            deck[11]=("King of Clubs");
            deck[12]=("Ace of Clubs");

            deck[22]=("Jack of Diamonds");
            deck[23]=("Queen of Diamonds");
            deck[24]=("King of Diamonds");
            deck[25]=("Ace of Diamonds");

            deck[35]=("Jack of Hearts");
            deck[36]=("Queen of Hearts");
            deck[37]=("King of Hearts");
            deck[38]=("Ace of Hearts");

            deck[48]=("Jack of Spades");
            deck[49]=("Queen of Spades");
            deck[50]=("King of Spades");
            deck[51]=("Ace of Spades");
        }
    }
}
private void perfectShuffle(){
    Deck();
    for (int i=0; i<27; i++){
        deck[i]=deck[i+26];
    }
    for (int i=0; i<52; i++){
        System.out.println(deck[i]);
    }
}

1 Answer 1

4

perfectShuffle does not have access to the local variables locked away inside of Deck(). You need to grab the value that Deck returns, and make good use of it:

private void perfectShuffle(){
    String[] myDeck = Deck();
    for (int i=0; i<27; i++){
        myDeck[i]=myDeck[i+26];
    }
    for (int i=0; i<52; i++){
        System.out.println(myDeck[i]);
    }
}

Likewise, you need to make Deck() actually return that string array, as you have declared the method to return a String[]:

public String[] Deck(){
    String[] deck = new String[52];

    //Populate Deck 2-10
    for (int i=0; i<52; i++){
        // blah blah blah
    }

    return deck;
}
Sign up to request clarification or add additional context in comments.

3 Comments

MattBot does not recognize this "hu-man" of which you question
Thanks for the compliments, I've just been around for a while.
yeah i had to wait 8 minutes lol, ive been spamming it i cant upvote it cuz i dont have nuff rep

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.