Hi there... I'm pretty new to java, just learning arrays now. I've written a program that deals a "poker hand" to 4 players, using methods, but the problem with that is sometimes the same card gets dealt more than once. I'm now trying to use a boolean array of size 52, with each card initialized to false... and when one gets chosen, it changes to true (so you can't choose a card if it's already true).. And truth be told I really have no clue what to do except
boolean[] deck = new boolean[52];
can anyone give me any insight..? I've no idea where to place it or what else to do. Thanks a bunch (: Sorry if this is a really juvenile question!
Here is my original code:
import javax.swing.JOptionPane;
public class Poker
{
public static void main (String[]args)
{
int face = 0, suit = 0;
int player = 0, round = 0;
System.out.print("Player 1\tPlayer 2\tPlayer 3\tPlayer 4\n");
for (round = 1; round <= 5; round++) //round of cards dealt
{
for (player = 1; player <= 4; player++)
{
face = 1 + (int) (Math.random() * 13);
suit = 1 + (int) (Math.random() * 4);
cardNumber(face);
cardSuit(suit);
if (player % 4 == 0)
System.out.println();
}
}
}
public static void cardNumber (int face)
{
if (face != 10)
System.out.print(" ");
switch (face) {
case 1: System.out.print("A of ");
break;
case 2: System.out.print("2 of ");
break;
case 3: System.out.print("3 of ");
break;
case 4: System.out.print("4 of ");
break;
case 5: System.out.print("5 of ");
break;
case 6: System.out.print("6 of ");
break;
case 7: System.out.print("7 of ");
break;
case 8: System.out.print("8 of ");
break;
case 9: System.out.print("9 of ");
break;
case 10: System.out.print("10 of ");
break;
case 11: System.out.print("J of ");
break;
case 12: System.out.print("Q of ");
break;
case 13: System.out.print("K of ");
break;
}
}
public static void cardSuit (int suit)
{
switch (suit) {
case 1: System.out.print("Diamonds");
break;
case 2: System.out.print("Hearts");
break;
case 3: System.out.print("Spades");
break;
case 4: System.out.print("Clubs");
break;
}
System.out.print("\t");
}
}