I am working on a poker program. I am having some issues figuring out how to shuffle. I have to use arrays. I can't use enums or Lists. i know there are much better ways to make this program but the point is to understand arrays.
I am having some issues figuring out how to shuffle my deck of cards. I'm trying to keep this as simple as possible so I have one class to get the cards of the deck and shuffle them.
import java.util.Arrays;
import java.util.Random;
public class Card
{
String[] suits = { "Spades", "Clubs", "Hearts", "Diamonds" };
String[] values = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
public Card()
{
}
public void getCards()
{
for(int indexSuit = 0; indexSuit < suits.length; indexSuit++)
{
String suit = suits[indexSuit];
System.out.print(suit + " ");
for(int indexType = 0; indexType < values.length; indexType++)
{
String type = values[indexType];
System.out.print(type + " ");
}
}
}
public void shuffle(String[] suit, String[] value)
{
Random rndSuits = new Random();
Random rndType = new Random();
for(int indexSuit = suits.length - 1; indexSuit > 0; indexSuit--)
{
int index = rndSuits.nextInt(indexSuit + 1);
String temp = suits[indexSuit];
suits[indexSuit] = suit[index];
suit[index] = temp;
System.out.print(temp);
for(int indexType = values.length -1; indexType > 0; indexType--)
{
int index2 = rndType.nextInt(indexType + 1);
String temp2 = values[indexType];
values[indexType] = value[index2];
value[index2] = temp2;
System.out.print(temp2);
}
}
}
public void deal()
{
}
}
Here is my main:
public class FiveCardPoker
{
public static void main(String[] args){
Card timsCards = new Card();
timsCards.getCards();
timsCards.shuffle(args, args);
}
}
I was trying to write the shuffle method based on another question I found on here, but it was only for a single array. I'm not sure if logic is correct for the shuffle method. I'm also not exactly sure how to call it in my main method.
How Do I get my arrays from the Card class to the Main class when I call timsCards.shuffle?
EDIT: So I have tried editing it like this, but it doesn't seem to be doing anything.
public void shuffle()
{
Collections.shuffle(Arrays.asList(suits));
Collections.shuffle(Arrays.asList(values));
System.out.println(Arrays.toString(values) + " of " + Arrays.toString(suits));
}