Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class CardDeck extends java.util.Stack<Card> {
- public CardDeck() {
- for(int i = 0; i < 4; i++) {
- for (int j = 0; j < 13; j++) {
- this.push(new Card(i, j+1));
- }
- }
- }
- private void swapCards(int i, int j) {
- Card tempCard = get(i);
- set(i, get(j));
- set(j, tempCard);
- }
- public void shuffle() {
- for (int i = 0; i < this.size(); i++) {
- int j = (int) (Math.random() * 52);
- swapCards(i, j);
- }
- }
- public Card dealCard() {
- return pop();
- }
- public String toString() {
- StringBuilder sb = new StringBuilder();
- for (Card c : this) {
- sb.append(c.getSuit()).append("/").append(c.getValue()).append(", ");
- }
- return sb.toString();
- }
- }
Add Comment
Please, Sign In to add comment