0

I'm sorry about how vague this is, but there's just too much code to put up.

It's a game of Five Card Stud. Basically I'm attempting to add objects to an arraylist inside of another arraylist.

Here's where I create the players array and add an array from the Hand class to it, at least I think that's what's happening:

players = new ArrayList<Hand>();
for(int index = 0; index < playerCount; index++)
{
    players.add(new Hand());
}

Later I attempt to add cards to the Hand array within the players array in a circular deal. As there are five cards, the first loop goes five times. The second goes for the length of the players array (the total number of players) and should add a single card each time.

for(int dealt = 0; dealt <= 5; dealt++)
{
    for(int index = 0; index <= players.size(); index++)
    {
        //what goes here????
    }
}

There is a deal method in the Deck class initialized by:

myDeck = new Deck();

....but I'm not sure how to apply it to the 'sub-array.'

This is a tall order I feel, so thanks in advance!

1 Answer 1

1
for(int dealt = 0; dealt <= 5; dealt++)
{
    for(int index = 0; index <= players.size(); index++)
    {
        players.get(index).addCard();
    }
}

Does the addCard method take any parameters?

Right now every player will get 5 cards.

Sign up to request clarification or add additional context in comments.

4 Comments

addCard inside the Hand method does take the parameter (Card card). How will that change things?
Then you'll have to add a card to the addCard() method call. Does card have a parameterless constructor?
FORGET ADDCARD! Looking over another premade class called deck, I found a method simply called deal which takes no parameters and does what I need. When I swap in .deal() for .addCard() it says "cannot find symbol - method deal()"
I initialize Deck with:myDeck = new Deck();

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.