Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class StackOfCards
- {
- public static final int SIZE = 52;
- private Stack<Card> deckOfCards;
- public StackOfCards()// creates deck of cards
- {
- DeckOfCards deck = new DeckOfCards();
- deck.shuffle(52);
- Stack<Card> arrayStack = new Stack<Card>();
- int i = 0;
- for(int suit = 1; suit <= 4; suit++)
- for(int face = 1; face <= 13; face++)
- arrayStack.push(deckOfCards.deal());
- }
- public Card deal()// deals one card at a time
- {
- Card card = null;
- if (deckOfCards.size() < SIZE)
- deckOfCards.pop();
- else
- System.out.println("The deck is empty.");
- return card;
- }
- public int cardsLeft()// shows remaining cards in the deck
- {
- int cardsLeft;
- cardsLeft = SIZE - deckOfCards.size();
- return cardsLeft;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement