CIT 591 Makeup Assignment: Counting Bridge Hands
Fall 2008, David Matuszek

Purposes of this assignment

General idea of the assignment

Count a bridge hand. We will use a slightly simplified counting algorithm in this assignment.

General information

A bridge deck is a deck of 52 cards. Each card belongs to one of four suits (Clubs, Diamonds, Hearts, or Spades) and has one of thirteen values (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King). So, 5×13=52.

A bridge hand consists of exactly thirteen cards, chosen at random from the bridge deck. When playing bridge, some hands are better than others. Counting a bridge hand means giving a number that tells how good it is (higher numbers are better).

To count a hand, you count high card points, count distribution points, and add the two numbers together for a final count.

High card points = 4 times the number of Aces, plus 3 times the number of Kings, plus 2 times the number of Queens, plus one for each Jack.

A void is when you have no card in a particular suit; a singleton is when you have only one card in a suit; and a doubleton is when you have only two cards in a suit.

Distribution points = 3 times the number of voids, plus 2 times the number of singletons, plus the number of doubletons.

Hand count = High card points + Distribution points.

Programming details

Create a project BridgeHand containing a package bridge. Use the following starter classes:

package bridge;

public enum Suit {
package bridge;

public class Card {
    String value;
    Suit suit;
    public Card(String value, Suit suit) {
        this.value = value;
        this.suit = suit;
    public boolean equals(Object object) {

package bridge;

public class Hand {
    Card[] cards;   // Should be exactly 13 cards
    public Hand(String hand) {
    public Card[] getCards() {
        return cards;

The input to the Hand constructor should be a string of thirteen tokens, separated by spaces. Each token should consist of one character for the value (or two, in the case of 10) and one character for the suit. For example:
     "3H 5S KD KC 10S AD 4D 6S QS 10H KS JD 2S"
(where A=Ace, J=Jack, Q=Queen, K=King, C=Clubs, D=Diamonds, H=Hearts, and S=Spades). As you can see from this example, the cards are given in no particular order.

The Hand constructor should take a string of the above form, and populate its cards array. It should throw an IllegalArgumentException if the parameter does not describe exactly thirteen cards. JUnit test this by calling the getCards method and checking that the correct cards are created, or that the exception is thrown.

The Card class should override both equals and toString. The equals method should return false if its parameter is not a Card. The toString method should produce a two- or three-character string, such as "3H" or "10S". JUnit test these methods.

The Hand class should provide the methods
     int getHighCardPoints()
     int getDistributionPoints()
     int getHandCount()

with the meanings as described above. These methods should be JUnit tested.


This is an individual assignment. You will not work with a partner.

The grade you get on this makeup assignment will replace the lowest grade you got on a previous assignment (assignments 1 through 9 only). In other words, if you get a lower grade on this assignment than on any previous assignment, it will still replace the lowest earlier grade.

Due date

Monday, December 1, before Midnight. We may or may not accept the assignment after this date, so be sure to get it in on time. Zip your package and hand it in via Blackboard.