Class sketch

Decide what kinds of information the class needs to "remember", and what are the most important methods for it to have.

For example, a Posn class representing a two-dimensional Cartesian coordinate pair would presumably contain two pieces of information: the x and y coordinates, both of which might be of type double (or perhaps int, if that were what you needed). A Date class would presumably contain a year, a month, and a day; you would need to decide at this point how you want to represent each of those. You can write this information down as a simple Java comment:

/**
 * Date has three int variables year, month, and day.
 */

Also write down the most important methods the class should provide, at least to the point of choosing a method name and a contract. Later on, you may discover that you need additional methods, or that your first guess at the contracts for these was wrong, in which case you can come back and change things.

/**
 * dayOfYear operates on a Date and returns an int.
 */

/**
 * before operates on a Date, takes another Date as an explicit
 * parameter, and returns a boolean (is this Date before the other
 * Date?)
 */

/**
 * daysLater operates on a Date and takes an int as an explicit
 * parameter, and returns another Date the specified number of days
 * later (or earlier, if the int is negative).
 */


Last modified: Fri Feb 20 09:50:59 EST 2009
Stephen Bloch / sbloch@adelphi.edu