Introduction to OOP: Chapter 8: The Solitaire Game [next] [previous] [audio] [real] [text]

The class card

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

		// access attributes of card
	public int    	rank ()  	{ return r; }
	public int     	suit()  	{ return s; }
	public boolean	faceUp()	{ return faceup; }
	public int    	color() 	{
		if (suit() == heart || suit() == diamond)
			return red;
		return black; }

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

		// static data fields for colors and suits
	final static int width = 50;
	final static int height = 70;
	final static int red = 0;
	final static int black = 1;
	final static int heart = 0;
	final static int spade = 1;
	final static int diamond = 2;
	final static int club = 3;

		// data fields
	private boolean faceup;
	private int r;
	private int s;
}
Intro OOP, Chapter 8, Slide 3