[Solved] I am having difficulty with my deal method


There is a lot of things wrong with this code. Your problem is, because you are randoming more and more instead of using te ran variable you declared at the beggining of deal method. After you declared your ran variable, don’t do dealer.nextInt(deck.length), replace it with ran.

Your shuffling is not really shuffling, check this: Random shuffling of an array.

Comparing (like if(something == false)) should be done with ==, you are doing it with = (but you probably just pasted it wrong).

In your getter this numberOfCardsInDeck = NUMBER_OF_CARDS; is wrong, unless you wanted to ‘refresh’ a deck instead of just get a number of cards, but I don’t think so, remove that line.

Triple for in your constructor is wrong, you need only the first one, it doesn’t make a difference here (except performance), but fix it.

Also I suggest rewriting all this, do a Card object (class) with suit and rank enums, make a Deck object with List of Card objects, make a deck.getCard() method that removes the last card from the deck, make the deck.shuffle() method that shuffles deck (you will have a List of Cards now, not an array, so you will be able to do Collections.shuffle(cardList), simple).

Also, change this:

if (deck[dealer.nextInt(deck.length)] == false)
            dealer.nextInt(deck.length);

To something like this:

while (deck[ran] == false)
            ran = dealer.nextInt(deck.length);

5

solved I am having difficulty with my deal method