I have to simulate shuffling and dealing of card(any card game).
What i have done is created, enum types of Suit and Rank in a class called Card and the constructor
public Card(Suit suit, Rank rank)
if(suit ==null || rank ==null)
throw new NullPointerException(rank+" , "+suit);
this.suit = suit;
this.rank = rank;
i think i have to use an arrayList to put a rank and its corresponding suit, thus shuffling it but can't figure out how.
Any help would be highly appreciated!!
Create a Deck class that holds an ArrayList<Card>. In the Deck class have a shuffle() method that shuffles the arraylist via Collections.shuffle(...). If you search this forum or the Sun fora you'll find many examples of this as it is an assignment that has been given to students for years. Best of luck.
The first hit in my Google search: Enums
You'll find this and many more goodies on Google.
Thank you. I shall implement what you've suggested.