Deck.java - package BlackJack import jdk.internal.org.objectweb.asm.tree.analysis.Value import java.util.ArrayList import java.util.Random The array for

Deck.java - package BlackJack import...

This preview shows page 1 - 3 out of 3 pages.

package BlackJack; import jdk.internal.org.objectweb.asm.tree.analysis.Value; import java.util.ArrayList; import java.util.Random; /** * The array for deck * A deck including 52 cards */ public class Deck { private ArrayList<Card> myCards; public Deck() { this.myCards = new ArrayList<Card>(); } public void createDeck() { for (Suit suit : Suit.values()) { for (Number number : Number.values()) { this.myCards.add(new Card(suit, number)); } } } public void shuffle() { Random ran = new Random();// random number generator ArrayList<Card> temp = new ArrayList<Card>();//temporary card deck int j; int size = this.myCards.size(); for (int i = 0; i < size; i++) { j = ran.nextInt((this.myCards.size() - 1) + 1);//get a random card j to swap i's value temp.add(this.myCards.get(j)); this.myCards.remove(j); } this.myCards = temp; } public Card getCard(int n) { return this.myCards.get(n); } public void addCard(Card add) { this.myCards.add(add); } public void removeCard(int n) { this.myCards.remove(n); } /** * deal the top card at the deck */ public void deal(Deck top) { this.myCards.add(top.getCard(0)); top.removeCard(0); }
Image of page 1
public String toString() { String cardListOutput = ""; for (Card aCard : this.myCards) {
Image of page 2
Image of page 3

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture