So I have to deal 5 cards to 4 players, but what is messing me up is that I am supposed to ask for the user to enter 4 names and then it should print out their name and their deck. However, when I enter four names it just takes the first name and uses it for all 4. Can somebody help modify this? Please and Thank you!
import java.util.Scanner;
public class CSC240_DealingDecks
{
public static <Players> void main (String args[] )
{
Scanner scanner = new Scanner(System.in);
{
int count = 0;
{
System.out.println("Please enter the names");
String playerName = scanner.next();
String player = "Players";
count++;
String[] SUITS =
{
"Clubs", "Hearts", "Spades", "Diamonds"
};
String[] RANKS =
{
"Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King"
};
// initialize deck
int n = SUITS.length * RANKS.length;
String[] deck = new String[n];
{
for (int i = 0; i < RANKS.length; i++)
{
for (int j = 0; j < SUITS.length; j++)
{
deck[SUITS.length*i + j] = RANKS[i] + " of " + SUITS[j];
}
}
// shuffle
for (int i = 0; i < n; i++)
{
int r = i + (int) (Math.random() * (n-i));
String temp = deck[r];
deck[r] = deck[i];
deck[i] = temp;
}
// print shuffled deck
for (int i = 0; i < 4; i++)
{
System.out.println( playerName + (i + 1));
for (int j = 0; j < 5; j++)
{
System.out.println(deck[i + j * 4] + " (Card " + (i + j `* 4) + ")" + "\n");
}
}
}
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire