Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- public class CardDeck {
- String[] faces = {
- "A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K" };
- String[] suits = { "Clubs", "Hearts", "Diamonds", "Spades" };
- Card[] cards = new Card[52];
- int max = cards.length;
- public CardDeck() {
- int c = 0;
- for (int s=0; s<suits.length; s++) {
- for (int f=0; f<faces.length; f++) {
- cards[c++] = new Card(faces[f], suits[s]);
- } // end for f
- } // end for s
- } // end default constructor
- public String toString() {
- String theString = "";
- for (int i=0; i<52; i++) {
- theString += cards[i].toString()+"\n";
- } // end for i
- return theString;
- } // end toString()
- public Card deal() {
- Random r = new Random();
- int i;
- i = r.nextInt(max);
- Card temp = cards[i];
- cards[i] = cards[--max];
- return temp;
- } // end deal()
- public int getLength() {
- return max;
- } // end getLength()
- } // end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement