I want to shuffle the cardList and valueList with algorithm, but when i use the shuffle collection for each one, they use different algorithm. So when i pull a card it will be a random card from the deck and the same card does not come up again.
public class BlackJack {
public static void main(String[] args) {
Random rand = new Random();
Scanner input =new Scanner(System.in);
ArrayList<String> cardList= new ArrayList<String>();
ArrayList<String> cardShuffle= new ArrayList<String>();
ArrayList<Integer> valueList= new ArrayList<Integer>();
ArrayList<String> valueShuffle= new ArrayList<String>();
cardList = card(cardList);
valueList = value(valueList);
Collections.shuffle(cardList);
Collections.shuffle(valueList);
System.out.println(cardList);
System.out.println(valueList);
}
private static ArrayList card(ArrayList<String> cardList){
String cards = null;
String suits = null;
int cardCount = 0;
for(int s = 1;s<5; s++){
switch (s){
case 1: suits = " of Heart"; break;
case 2: suits = " of Diamond"; break;
case 3: suits = " of Spades"; break;
case 4: suits = " of Clubs"; break;
}
for(int c = 1;c<14; c++){
switch (c){
case 1: cards = "2"; break;
case 2: cards = "3"; break;
case 3: cards = "4"; break;
case 4: cards = "5"; break;
case 5: cards = "6"; break;
case 6: cards = "7"; break;
case 7: cards = "8"; break;
case 8: cards = "9"; break;
case 9: cards = "10"; break;
case 10: cards = "Jack"; break;
case 11: cards = "Queen"; break;
case 12: cards = "King"; break;
case 13: cards = "Ace"; break;
}
cardList.add(cardCount, cards + suits);
cardCount++;
}
}
return cardList;
}
private static ArrayList<Integer> value(ArrayList<Integer> valueList){
int v = 2;
int counter = 1;
for(int c = 1;c<52; c++){
if(v > 10){
v = 10;
}
valueList.add(v);
v++;
counter++;
if(counter>13){
counter = 1;
v=2;
}
}
return valueList;
}
}
Edit: I made a second class as @Cinnam had suggested, then used a For int to shuffle the cards with a random number.
public class BlackJack {
public static void main(String[] args) {
Random rand = new Random();
Scanner input =new Scanner(System.in);
ArrayList<String> cardList= Cards.card();
ArrayList<Integer> valueList= Cards.value();
ArrayList<String> cardShuffle= new ArrayList<String>();
ArrayList<Integer> valueShuffle= new ArrayList<Integer>();
int r = 0;
for(int i = 0; i < 52; i++){
r = rand.nextInt(52);
cardShuffle.add(i,cardList.get(r));
valueShuffle.add(i,valueList.get(r));
}
System.out.println(cardShuffle);
}