Search code examples
javablackjack

{close} CAN't use the Object. Reason: haven't had a place to store the player


I do the first part but the playeri can't use in the second part because I forget to create an array to store it:

Player[] player = new Player[11];//solution add a array to store the player

for(int i=1;i<=10;i++) {
boolean finishplayeri = false;
Player playeri = new  Player("player"+i); //if you don't create a array to store your player
player[i] = playeri;
}

second part:

for(int i=1;i<=noofplayer;i++) { 
player[i].addCard(theDeck.NextCard());  // in here your player[i] will be error
player[i].addCard(theDeck.NextCard());          
player[i].printHand(false);
}

Question: CAN't use the Object. Reason: haven't had a place to store your player. method: create an array to store my player.


Solution

  • You have to put your Players in container to handle it. You don`t store your players anywhere.