I have an ArrayList which stores 52 card objects like so:
public class Pack
{
private ArrayList<Card> cards;
private Card RandomCard;
public static void main(String[] args) {
ArrayList<Card> cards = new ArrayList<Card>();
cards.add(new Card('C','A'));
cards.add(new Card('C','2'));
cards.add(new Card('C','3'));
etc..
I also have this method which generates a random number to grab a random object from my ArrayList.
public Card getRandomCard()
{
int number = (int) (Math.random() * 52.0);
return RandomCard;
}
This compiles but when I test it I get returned 'null'. I have to include this method! Any suggestions?
RandomCardis definitely null if this is your actual code. If it's sudo, have you tested to make sure that the random number is within the array range? Also, if you want anint, why do you say52.0? Wouldn't52be better?