Something to do to prepare for the BONUS VALUE PAK AP COMPUTER SCIENCE TEST
Write a Card class that meets the following specifications:
- It has two fields: a rank and a suit, each represented with a character (char data type). There should be static arrays that contain all of the possible values of ranks and suits:
- Ranks have the following values: '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A'
- Suits have the following values: 'S', 'H', 'D', 'C'
- There should be a toString() method that returns the symbol of a card (9S, QD, 3C, e.g.).
- Cards must be comparable to other Cards based on card ranks.
- There should be a method to test if two Cards are equal (again, based on ranks); this should be separate from a compareTo() method.
Write a Deck class that meets the following specifications:
- The constructor should create and store a standard deck of 52 playing cards. Hint: Iterate on Card.RANKS and Card.SUITS. Whether to use Card[] or ArrayList<Card> is up to you. If you use an array, you will need a field that keeps track of the number of cards left in the deck.
- There should be a deal() method that returns a random card from the deck.
- When a deck is printed, all of the remaining cards should be printed.
- There should be a size() method, indicating the number of cards left in the deck.
- There should be an isEmpty() method, which returns true if there are no cards left in the deck.
In main(), write a method called pokerRank() that returns a string that describes the hand. The possible return values are:
- "ROYAL FLUSH"
- "STRAIGHT FLUSH"
- "FOUR OF A KIND"
- "FULL HOUSE"
- "FLUSH"
- "STRAIGHT"
- "THREE OF A KIND"
- "TWO PAIR"
- "ONE PAIR"
- "GARBAGE"
If the College Board makes you write something as time-consuming as this problem on the actual AP test, by all means sue them. I'll testify. You'll lose your case, but I promise that I will rant when I take the stand.