/*
* War Simulation
* Deck Class
* contains 52 cards 13 of each suit
*
* 3/6/10
*
* @author D. Bryce Miller
*/
import java.util.*;
public class Deck
{
//the deck
private LinkedList m_theDeckOfCards;
// suits
private Card m_spades;
private Card m_hearts;
private Card m_diamonds;
private Card m_clubs;
//card removed when dealing
private Card removedCard = new Card();
//constructor - creates an empty linked list
public Deck()
{
m_theDeckOfCards = new LinkedList();
}
//adds all the cards to the deck
public void fillDeck()
{
for (int i=2; i<15; ++i)
{
m_theDeckOfCards.addLast(m_spades = new Card("spades", i));
m_theDeckOfCards.addLast(m_hearts = new Card("hearts", i));
m_theDeckOfCards.addLast(m_diamonds = new Card("diamonds", i));
m_theDeckOfCards.addLast(m_clubs = new Card("clubs", i));
}
System.out.println(m_theDeckOfCards);
}
/*picks a random card from the deck to deal
**by removing a random card from within the deck
*/
public Card deal()
{
Random generate = new Random();
removedCard = m_theDeckOfCards.remove(generate.nextInt(m_theDeckOfCards.size()));
System.out.println(removedCard);
return removedCard;
}
// Issue here
public static void main(String[] args)
{
Deck test = new Deck();
test.fillDeck();
test.deal();
}
}
This post has been edited by Dogstopper: 08 March 2010 - 03:25 PM
Reason for edit:: Post between code tags and no smilies in code...

New Topic/Question
Reply
MultiQuote











|