Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- public class Deck
- {
- private ArrayList<Card> deck;
- /**
- * Fills a deck with the 52 unique cards
- * @param Sets the suit rank and value of the 52 cards
- */
- public Deck()
- {
- deck = new ArrayList<Card>();
- String suit = "";
- String rank = "";
- int value;
- for(int i = 1; i<=13;i++)
- {
- for(int j =1; j<=4;j++)
- {
- if (j == 1)
- suit = "Spades";
- else if(j == 2)
- suit = "Diamonds";
- else if (j==3)
- suit = "Clubs";
- else if (j == 4)
- suit = "Hearts";
- if (i == 1)
- rank = "Ace";
- else if(i == 2)
- rank = "Two";
- else if (i == 3)
- rank = "Three";
- else if (i == 4)
- rank = "Four";
- else if (i == 5)
- rank = "Five";
- else if (i == 6)
- rank = "Six";
- else if (i == 7)
- rank = "Seven";
- else if (i == 8)
- rank = "Eight";
- else if (i == 9)
- rank = "Nine";
- else if (i == 10)
- rank = "Ten";
- else if (i == 11)
- rank = "Jack";
- else if (i == 12)
- rank = "Queen";
- else if (i == 13)
- rank = "King";
- if (i == 1)
- value = 11;
- else if (i<=10)
- value = i;
- else
- value = 10;
- deck.add(new Card(value, rank, suit));
- }
- }
- }
- /**
- * Returns the deck
- * @return the ArrayList deck
- */
- public ArrayList<Card> getDeck()
- {
- return deck;
- }
- /**
- * Gets a specific card in the deck based off its position in the Array List
- * @return a Card in the deck
- */
- public Card getCardInDeck(int n)
- {
- return deck.get(n);
- }
- /**
- * @returns A String representation of the deck.
- */
- public String toString()
- {
- String showDeck = "";
- for (int i=0; i<52; i++)
- {
- showDeck += deck.get(i) + "\n";
- }
- return showDeck;
- }
- }
- public class DeckTester
- {
- public static void main (String[] args)
- {
- Deck d = new Deck();
- System.out.println(d);
- System.out.println();
- System.out.println(d.getCardInDeck(32));
- System.out.println(d.getCardInDeck(1));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement