CSci 581: Obj.-Oriented Design & Programming
Spring Semester 1999
Lecture Notes


Solitaire Case Study (Budd's UOOPJ, Ch. 9)

This is a set of "slides" to accompany chapter 9 of Timothy Budd's textbook Understanding Object-Oriented Programming with Java (Addison-Wesley, 1998).


The Solitaire Game


Class Card

import java.awt.*;

public class Card 
{ 
  // public constants for card dimensions
    public final static int width = 50;
    public final static int height = 70;

  // public constants for card suits
    public final static int heart = 0;
    public final static int spade = 1;
    public final static int diamond = 2;
    public final static int club = 3;

  // constructors
    public Card (int sv, int rv) 
    { s = sv; r = rv; faceup = false; }

  // mutators 
    public final void flip() { faceup = ! faceup; }

  // accessors
    public final int rank () { return r; }

    public final int suit() { return s; }

    public final boolean faceUp() { return faceup; }

    public final Color color() 
    {   if (faceUp())
            if (suit() == heart || suit() == diamond)
                return Color.red;
            else
                return Color.black;
        return Color.yellow;
    }

    public void draw (Graphics g, int x, int y) 
    {   /* ... */   }

  // internal data fields
    private boolean faceup;  // card face exposed?
    private int r;           // card rank
    private int s;           // card suit
}


Notes on Class Card