My textbook gave me this code saying that it'll create a new set of 52 cards. I don't really understand what it does, because the methods I see on google is very different from this. I'm confused about what the "index" variable does and how can I print this method? I do have a printdeck method but how would I call that method if this method doesn't return any number?
public static void buildDeck () {
Card[] deck = new Card [52];
int index = 0;
for (int suit = 0; suit <=3; suit++) {
for (int rank = 1; rank <= 13; rank++) {
deck[index] = new Card (suit, rank);
index++;
}
}
//here is my printDeck method
public static void printCard (Card c) {
String[] suits = { "Clubs", "Diamonds", "Hearts", "Spades" };
String [] ranks = { "nart", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10", "jack", "Queen", "king" };
System.out.println (ranks[c.rank] + " of " + suits[c.suit]);
}
public static void printDeck (Card[] deck) {
for (int i = 0; i< deck.length; i++) {
printCard (deck[i]);
}
}
I'll appreciate any help, thanks!