Advertisement
Guest User

Untitled

a guest
May 4th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. public class StackOfCards
  2. {
  3. public static final int SIZE = 52;
  4. private Stack<Card> deckOfCards;
  5.  
  6. public StackOfCards()// creates deck of cards
  7. {
  8. DeckOfCards deck = new DeckOfCards();
  9. deck.shuffle(52);
  10.  
  11. Stack<Card> arrayStack = new Stack<Card>();
  12.  
  13. int i = 0;
  14. for(int suit = 1; suit <= 4; suit++)
  15. for(int face = 1; face <= 13; face++)
  16. arrayStack.push(deckOfCards.deal());
  17. }
  18. public Card deal()// deals one card at a time
  19. {
  20. Card card = null;
  21.  
  22. if (deckOfCards.size() < SIZE)
  23. deckOfCards.pop();
  24. else
  25. System.out.println("The deck is empty.");
  26.  
  27. return card;
  28. }
  29. public int cardsLeft()// shows remaining cards in the deck
  30. {
  31. int cardsLeft;
  32. cardsLeft = SIZE - deckOfCards.size();
  33.  
  34. return cardsLeft;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement