CardDeck - for(int i = 0; i < rand.length; i++)...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
/******************************************************************************* * Discription: Creates a full deck of cards shuffled and ready * to be dealt. ******************************************************************************/ import java.util.Arrays; import java.util.Collections; import java.util.Random; i public class CardDeck extends LinkedList { //52-card deck char[] number = {'A','1','2','3','4','5','6','7','8','9','J','Q','K'}; char[] suit = {'H', 'S', 'C', 'D'}; String[] rand = new String[52]; LinkedList deck; /************************************************************************** * CardDeck() - constructor creates a deck of shuffled cards **************************************************************************/ public CardDeck() { deck = new LinkedList(); int count=0; for(int i = 0; i < suit.length; i ++) { for(int k = 0; k < number.length; k++) { rand[count] = suit[i]+""+number[k]; count++; } } Collections.shuffle(Arrays.asList(rand), new Random());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for(int i = 0; i &lt; rand.length; i++) { deck.add(new Card(rand[i].charAt(0), rand[i].charAt(1))); } } /************************************************************************** * getLength() - gets the size of the deck * @return get size of deck **************************************************************************/ public int getLength() { return deck.size(); } /************************************************************************** * getCard() - returns a card * @return card */ public Comparable&lt;Object&gt; getCard() { return deck.get(); } /************************************************************************** * addCard() - adds a card to the deck * @param card **************************************************************************/ public void addCard(Comparable&lt;Object&gt; card) { deck.add(card); } }...
View Full Document

Page1 / 2

CardDeck - for(int i = 0; i &amp;amp;lt; rand.length; i++)...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online