last updated: Mon Mar 4 09:59:05 EST 2002

CS1007
Spring 2002
Homework #3
due Thu Mar 7, by 6AM -- electronic submission

hardcopy due IN CLASS: 11.05AM cs1007-002; 2.45PM cs1007-001

goal.
The goals of this assignment are to:

  1. learn how to define your own class
  2. learn how to use arrays

blackjack.
You need to write a program to play the game of Blackjack. Note that the rules outlined here are simplified for the homework assignment; they do not involve betting or knowing what other players' cards are. The rules are as follows.

program.

  1. (0.75 points total) Begin with the Card class we wrote during lecture and modify it as follows:
    1. Write a method called public int getScore() which returns the score of the card as described in the rules (above). (0.50 points)
    2. Write a method called public boolean isAce() which returns true if the card is an ace and false if it is not. (0.25 points)

  2. (1.25 points total) Start with the skeleton class Deck and complete it as follows:
    1. Declare any global constants you deem necessary for the class. (0.25 points)
    2. Declare a global variable array which represents a full deck of cards (i.e., 52 Card) and any other variables that you deem necessary for the class. (0.25 points)
    3. Write a constructor for the class that initializes global variables, as necessary, and performs any other initialization tasks that you deem necessary for the class. (0.25 points)
    4. Write a method called deal() that can be called to effectively deal one card from the deck (and return it to the caller). Note that you have to keep track of which cards have been dealt so that you only deal one of each suit/value combination. (0.50 points)

  3. (2.75 points total) Start with the skeleton create a class Player and FIRST rename it using your user name to be called <your_cunix_id>Player.java. For example, mine is called eis2003Player.java. Then complete the class as follows:
    1. Declare any global constants you deem necessary for the class. (0.25 points)
    2. Declare a global variable array which represents the player's hand (note that the maximum number of cards that can be dealt in Blackjack is 9 cards) and any other variables that you deem necessary for the class. Note: in the skeleton code, there is already a variable declared called deck. This is a reference to the global deck variable declared in the main program (which is provided to you). Don't change this line of code!! (0.25 points)
    3. Complete the constructor for the class that initializes global variables, as necessary, and performs any other initialization tasks that you deem necessary for the class. Note: in the skeleton code, there is a parameter passed to the constructor called deck0. This is a reference to the global deck variable declared in the main program (which is provided to you) and is used to initialize the local deck variable. Don't change this line of code!! (0.25 points)
    4. Write a method called public String toString() that returns a string version of the cards in the player's hand. (0.25 points)
    5. Write a method called public int getScore() that returns the score of the cards in the player's hand. (0.25 points)
    6. Write a method called public void hitMe() that receives a card from the dealer and stores it in the player's hand. Note that this method should update the score of the hand when a new card is added. (0.50 points)
    7. Modify the method called public void play(). The version included in the skeleton code plays a naive game of Blackjack, continually receiving new cards until the score of the player's hand exceeds 21. Modify this method to play use a smarter strategy. (1.0 points)

  4. (0.25 points total) Modify the Blackjack class as follows:
    1. Change the global variable definitions for dealer and player to use your player class instead of the generic class Player. (0.25 points)

sample run.
Below is a sample run. The unix command line is highlighted in bold font.

unix$ java Blackjack
PLAYER:
7S KH score 17
7S KH KD score 27

DEALER:
AC 5S score 6
AC 5S 2C score 8
AC 5S 2C 3S score 11
AC 5S 2C 3S AH score 12
AC 5S 2C 3S AH 8S score 20
AC 5S 2C 3S AH 8S KC score 30

you have gone bust; the dealer has gone bust --> nobody wins!

fun tournament.
For fun, we'll hold a tournament between everyone's working players, to see whose strategy works best. The winner(s) will receive RoboCupJunior t-shirts.

source code.
Your source code (i.e., your .java file) but be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }).

submission.
Follow the submission instructions carefully!!! If you don't, human intervention will be required to fix your mistakes, and you will lose 1 point.

  1. Name your player file properly.
    Your PLAYER file MUST be named <yourCUNIXusername>Player.java
    For example, mine is called eis2003Player.java.

  2. Submit your files electronically.
    You need to turn in ALL the Java source code, e.g., the files named Card.java, Deck.java, eis2003Player.java and Blackjack.java. Follow instructions on the assignments page.

  3. Turn in a harcopy of your program during THE FIRST 5 MINUTES OF class.
    Print out the homework template cover page (http://www.columbia.edu/~cs1007/hw-template.html) and fill it out.
    Staple the cover page to a hardcopy (print-out) of your program. You need to turn in ALL the Java source code, e.g., the files named Card.java, Deck.java, eis2003Player.java and Blackjack.java. Make sure your name is on all the papers you hand in!
    Bring the cover page and hardcopy to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class:
    cs1007-002: 11.05am
    cs1007-001: 2.45pm

points.
This assignment is worth 7 points (out of 100 for the semester). Distribution of points is: