What I am attempting to do is obtain a random value from my two arrays, which I have successfully done. My issue is that I am not receiving the correct output when the instance of an object from my Card class is created. I expect my output to be something like "2 of Hearts" or "Jack of Spades". Instead, I have no output but the code runs successfully.
Here is the code:
import java.util.Random;
public class Card {
private static final String deckRanks[] = {"King", "Queen", "Jack", "Ace", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
private static final String deckSuits[] = {"of Diamonds", "of Spades", "of Hearts", "of Clubs"};
public static void main(String[] args) {
}
public static String getRandomCard(){
String card;
Random cardSelector = new Random();
int randomRank = cardSelector.nextInt(deckRanks.length);
int randomSuit = cardSelector.nextInt(deckSuits.length);
card = deckRanks[randomRank] + " " + deckSuits[randomSuit];
return card;
}
@Override
public String toString(){
return getRandomCard();
}
}
And the class with the instance of the Card object:
public class CardHand {
public static void main(String[] args) {
Card cards = new Card();
cards.getRandomCard();
}
}