Jump to page content Jump to navigation

College Board

AP Central

AP Teacher Communities
AP Exams & College Enrollment
Click here to visit the SpringBoard Microsite
Print Page
Home > AP Courses and Exams > Course Home Pages > High/Low Card Game

High/Low Card Game

by Evelyn Rothman
Arthur L. Johnson High School
Clark, New Jersey

High/Low Card Game
  • Overview
    • Simulate a deck of playing cards
    • Shuffle the deck
    • Deal (5) cards into the hand
    • Turn over the first card
    • Leave the remaining (4) face down
    • The user must guess whether the next card is higher or lower
    • Turn over the next card
    • If the user guesses correctly, the game continues
    • If the use is guesses incorrectly, the game is over and the user loses
    • If the user guesses correctly (4) times, the game is over and the user wins
  • Objectives
    • Using classes to represent objects
      • Card 
      • CardDeck 
      • Hand 
    • Public and private methods
    • Using data structures
      • Two-dimensional array (card deck)
      • ArrayList or array (hand)
    • Using the compareTo method
      • Card class implements Comparable 
      • Order is the rank
    • Implementing the card deck shuffle
      • Each Card in turn is swapped with a random Card
  • Level
    • Advanced Placement Computer Science
      • Reinforces the objectives specified above
  • Time required
    Four or five 45 minute classes


Guide to the Teacher

Concepts
  • Create and use classes: CardCardDeck, Hand
  • The Comparable Interface
    • The Card class compareTo method compares the ranks of two Card objects
  • Data Structures: ArrayList, array
  • Create a permutation of objects (i.e., shuffle the CardDeck)
  • Create a GUI
Prerequisites

Before starting this project, students should have an understanding of the following:
  • Strings
  • Methods
  • Arrays and/or ArrayLists 
  • The Comparable Interface and the compareTo method
  • Classes and objects
  • Applets
Notes
  • I introduce this project in the Advanced Placement course to reinforce the concepts stated above. Before the students begin the High/Low applet, we work as a class on
    • the CardCardDeck and Hand classes 
      • Some methods are done as a class; others I have the students do individually
    • the creation of an ordered CardDeck 
    • an algorithm for shuffling the CardDeck 
    • dealing Cards 
  • After they complete the High/Low Card Game, students can go on to write programs for card games that are more complex, such as Blackjack or War.
  • For a greater challenge, consider games which require students to extend the Card class (e.g., card ranks differ from 2,3,...,Jack,Queen,King,Ace) and/or the CardDeck class (e.g., Old Maid eliminates one Queen: see http://saturn.cs.ukzn.ac.za/~robd/2005/courses/comp200/pracs/05prac06/oldmaid.html )
High/Low Card Game - Expected Results

Students will write the High/Low Card Game Applet which will behave as follows:
  • A new CardDeck is constructed and shuffled
  • A Hand of 5* Cards is dealt; the image of the first Card is shown face up, and the remaining 4 are face down (card back image)
  • The user guesses Higher/Lower
    • If the user is correct, the game continues
    • If the user is incorrect, the game ends
  • If the user guesses correctly 4 times (i.e., all card images a re face up) the user wins
  • Play Again
    • Re-initialize
      • New CardDeck, shuffle, deal
      • Variables re-initialized
Of course, the number of Cards in the Hand can be greater or less than five.

This lesson can be introduced using the included Card Project presentation (.ppt/225kb)

Completed code (.pdf/19kb) for the classes and applet are also included.

Evelyn Rothman is a member of the Computer Science Teachers Association (CSTA).


  ABOUT MY AP CENTRAL
    Course and Email Newsletter Preferences
  AP COURSES AND EXAMS
    Course Home Pages
    Course Descriptions
    The Course Audit
    Teachers' Resources
    Exam Calendar and Fees
    Exam Information
  PRE-AP
    SpringBoard®
  AP COMMUNITY
    About Electronic Discussion Groups
    Become an AP Exam Reader

Back to top