i need to put a new card and put it into the array but I’m not sure of the correct way to do it since everything I do will make it print null
Create a new Card and store it in the array.
Using nested enhanced for loops, for (Card suit : cards) and for (Card card : suit), print the card using System.out.println(card);
This should print the cards in a deck in order from the TWO of CLUBS to the ACE of SPADES.
import java.util.Arrays;
public class Card {
enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES };
enum Rank { TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE };
private final Suit suit;
private final Rank rank;
static final Suit[] allSuits = Suit.values();
static final Rank[] allRanks = Rank.values();
static final int DECK_COUNT = allSuits.length * allRanks.length;
public Card( int suit, int rank) { // Constructor
this.suit = allSuits[suit];
this.rank = allRanks[rank];
}
@Override
public String toString() {
return rank + " of " + suit;
}
public static void main(String[] args){
Card[][] cards = new Card[Card.allSuits.length][Card.allRanks.length];
for(Suit suit : Suit.values()){
for(Rank rank : Rank.values()){
}
}
System.out.println(Arrays.deepToString(cards));
}
}