@@ -0,0 +1,2842 @@
+package com.github.myyk.cracking.chapter7;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Set;%0A%0A/**%0A * Deck of Cards: Design a generic deck of cards. Explain how to subclass the data%0A *   structures to implement BlackJack%0A *%0A * BlackJack:%0A *   BlackJack could be implemented by keeping track of players hands. It would also%0A *   need to be able to calculate the value of the had from the cards in it. It would%0A *   need the concept of hidden versus revealed cards as well. I'm not sure enough how%0A *   split and other more advanced blackjack concepts work.%0A * Differences with the book's answer:%0A *   - I forgot about Enums in Java because of the lack of their usage in Scala. I think%0A *   using those for Suits is quite appropriate and better than what I did.%0A *   - I don't like that they added dealing of hands to the deck, this seems more of%0A *   a responsibility of the game as some games might require them to be dealt a certain%0A *   way because stacking the deck can be part of the game. I also don't really think a%0A *   Deck should know what a Hand is even.%0A *   - I'm not a huge fan of setDeckOfCards, I like setting the cards on the deck which%0A *   can be used to restore the deck to be full again when shuffling the hands into it.%0A *   Alternatively, a new deck could be created.%0A *   - Adding a discard could arguable be part of the Game instead, but they are usually%0A *   kind of the same across most games, where some don't care about an ordering and some%0A *   do. I think it's addition is not bad.%0A *   %0A */%0A// I'm being a bit lazy here by not creating other classes in other files and using%0A// comments as if they were%0Apublic class DeckOfCards%3CT /*extends Card*/ %3E %7B%0A  private ArrayList%3CT%3E deck;%0A  private ArrayList%3CT%3E discard;%0A  private Set%3CT%3E cards;%0A%0A  public void shuffle() %7B%7D%0A  public void shuffleDiscardWithDeck() %7B%7D%0A%0A  public PokerCard dealNextCard() %7B%0A    return null;%0A  %7D%0A%0A  public int cardsLeftInDeck() %7B return deck.size(); %7D%0A  public int cardsLeftInDiscard() %7B return discard.size(); %7D%0A%0A  public void putOnTop(Card card) %7B%7D%0A%0A  public void putOnBottom(Card card) %7B%7D%0A%0A  public void takeFromDiscard(Card card) %7B%7D%0A%0A  public static interface Card %7B    %0A  %7D%0A%0A  public static class PokerCard implements Card %7B%0A    int num;%0A    Suit suit;%0A%0A    public boolean isJack() %7B return num == 11; %7D%0A    public boolean isQueen() %7B return num == 12; %7D%0A    public boolean isKing() %7B return num == 13; %7D%0A    public boolean isAce() %7B return num == 1; %7D%0A%0A    public static interface Suit%7B%7D%0A    public static class Hearts implements Suit %7B%7D%0A    public static class Spades implements Suit %7B%7D%0A    public static class Clubs implements Suit %7B%7D%0A    public static class Diamonds implements Suit %7B%7D%0A  %7D%0A%0A  public static DeckOfCards%3CPokerCard%3E getDeckOfPokerCards() %7B%0A    // create DeckOfCards with 13 PokerCards of each suit%0A    return null;%0A  %7D%0A%7D

Add DeckOfCards