Your SlideShare is downloading. ×
  • Like
Ch11 Search & Sort
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Ch11 Search & Sort



  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Chapter 5 Black Jack
  • 2. Chapter Objectives
    • Provide a case study example from problem statement through implementation
    • Demonstrate how a set can be used to solve a problem
  • 3. Black Jack
    • Black Jack is a card game typically involving multiple players and a dealer
    • Each card in a hand is awarded points based upon its face value
    • Face cards are worth 10 points each
    • Numeric cards are worth their face value
    • Aces are worth either 1 or 11 points
  • 4. Black Jack
    • The goal of the game is to be closer to 21 than the dealer without going over 21
    • Black Jack is usually played with a shoe of cards (a collection of seven decks)
  • 5. Black Jack
    • For this case study, we define black jack as a one-player v.s. the dealer interactive card game
    • We will also limit the game to a single deck of cards rather than a shoe
    • The player begins the game by clicking a Deal button
  • 6. Black Jack
    • The player and the dealer are then dealt two cards
    • The player can see their own cards and one card of the dealer
    • The player then has the choice to hit (take another card) or stay (accept this hand as final for this game)
    • If the player busts (goes over 21) then the game is over
  • 7. Black Jack
    • Once the player elects to stay, the dealer then chooses to hit or stay
    • The dealer must hit on 16 or less and must stay otherwise
    • An Ace is considered to be 1 point rather than 11 points if otherwise it would cause the player or dealer to bust
  • 8. Black Jack - Initial Design
    • Our black jack game is made up of the components of the game, the function of the game, and the user interface
    • The components include cards, deck, and players hands
    • The function includes controlling the order of play, whether a player hits or stays, and the value of a players hand
  • 9. Black Jack - Initial Design
    • In this case study, there is a clear distinction between the low-level components of the game and the game itself
    • These low-level components (card, deck, hand) are also very well defined in terms of state and behavior
    • Thus a bottom-up approach to this design problem makes sense
  • 10. Black Jack - Initial Design
    • Bottom-up simply means that we will design the low-level components first and then work our way up to the driver
    • Other approaches include top-down and re-use based design
    • Keep in mind, these are simply frameworks not rigid models
    • Thus we will often find ourselves mixing these approaches even on the same system
  • 11. Black Jack - the Card Class
    • A Card object must represent:
      • the suit of the card (heart, diamond, club, or spade),
      • the value of the card (1 to 11),
      • the face of the card (ace, king, queen, six, two, etc.),
      • the image of the card
    • A Card object must also provide a constructor, operations to:
      • retrieve the suit, value, face, or image of the card,
      • an operation to change the value of an ace from 11 to 1
  • 12. Black Jack - the Deck Class
    • A deck is an unordered collection of unique cards
    • Thus a set is a perfect collection to represent a deck
    • The Deck class must include
      • the collection of Cards,
      • a method to retrieve a random card from the deck
  • 13. Black Jack - the Deck Class
    • We will also choose to instantiate a new deck at the beginning of each new game
    • This eliminates the possibility of ever having an “empty” deck during a game
  • 14. Black Jack - the Hand Class
    • A hand is a collection of unique cards that have been dealt to a player
    • A Hand object must keep track of:
      • the cards in the hand,
      • the count of the cards in the hand,
      • the value of the hand
    • A Hand object must also provide methods to:
      • add a card to the hand,
      • remove a card from the hand,
      • return the value of the hand,
      • provide a string representation of the hand
  • 15. Black Jack - the Hand Class
    • A Hand object must also provide a method to determine if an ace is in the hand and needs to be reduced in value from 11 to 1
    • As with a Deck, a set seems a reasonable collection to represent a Hand since each of the cards in the Hand are unique and order does not matter
  • 16. Black Jack - the BlackJack Class
    • Separating the function of the game from the user interface, we will have a BlackJack class to control the game and a BlackJackGUI class to provide the interface
    • The BlackJack class must represent
      • the hands of both players
      • the deck
  • 17. Black Jack - the BlackJack Class
    • This class must provide methods to:
      • deal the initial cards,
      • hit a particular player,
      • return the value of a player’s hand,
      • determine is a player has busted,
      • determine the winner of the game
    • The BlackJack class will use the Deck class to store the deck and the Hand class to represent each player
  • 18. Black Jack - the BlackJackGUI Class
    • The BlackJackGUI class will provide the user interface for our game
    • This class will provide:
      • a deal button,
      • buttons for the player to hit or stay,
      • a display of each player’s hand
      • a display of the winner of the game
  • 19. FIGURE 5.2 User interface design for BlackJack
  • 20. BlackJack - the BlackJackDemo Class
    • The BlackJackDemo class will serve as the driver for our system
    • This class simply creates an instance of BlackJackGUI and calls its display method
  • 21. FIGURE 5.1 Blackjack class diagram