My program is designed to draw 5 cards at random from a pack of cards. However, when I run it, the output is:
null null null null null
public class Poker {
static int numberOfPlayers;
public static void main(String[] args) {
drawComCards();
}
static void drawComCards() {
Card[] comCard = new Card[5];
for (int i = 0; i < comCard.length; i++)
comCard[i] = new Card();
for (int i = 0; i < comCard.length; i++)
System.out.print(comCard[i].getCard() + " ");
}
}
public class Card {
private String[] rank = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};
private String[] suit = {"clubs", "diamonds", "hearts", "spades"};
private String cardValue;
void Card() {
String cardOne = rank[(int) (Math.random() * rank.length)] + " of " + suit[(int) (Math.random() * suit.length)];
cardValue = cardOne;
}
String getCard() {
return cardValue;
}
}
I haven't thought about how to eliminate drawing the same card more than once yet.