I have this method called HandScore
that takes a Card array called hand
, and returns the value of the hand, by adding up all the ranks. It also adds 10, to any ranks that have a value greater than 10. However, when I try to run the code, it gives me a NullPointerException. I know why, but, I don't know how to fix it. Is there any feedback I can get?
public int HandScore(Card[] hand)
{
int total=0;
int[] rAnk=new int[0];
for(int i=0;i<hand.length;i++)
{
rAnk[i]=hand[i].rank;
total=total+rAnk[i];
}
if(hand.rank>10)
{
total=total+10;
}
return total;
}