©2005 Felleisen, Proulx, et. al.

3  Methods for Containment, Unions, and Self Referential Data

Methods and Containment Arrows

3.1  Problem (11.1.1)

Recall the problem of writing a program that assists a book store manager (cf. homework 1, problem 2). Add the following methods to the Book class:

  1. currentBook, which accepts a year and returns true only when the book was published in the given year;

  2. thisAuthor, which accepts an author and returns true only when the book was writted by the given author;

  3. sameAuthor, which accepts another book and returns true only when the two books have identical authors.

3.2  Problem (11.1.2)

Homework 1, problem 4 provides the data definition for a weather recording program. Design the following methods for the WeatherRecord class (you may assume that the high is greater than the low for all instances of TemperatureRange):

  1. withinRange, which determines whether today's high and low were within the normal range.

  2. rainyDay, which determines whether the precipitation is higher than some given value.

  3. recordDay, which determines whether the temperature broke either the high or the low record .

  4. same, which determines whether two different records represent the same information.

Last modified: Wednesday, January 19th, 2005
HTML conversion by TeX2page 2004-09-11