Design recipes and methods for composition
(10.1.1, 10.1.2)
Recall the problem of writing a program that assists a book store manager (see exercise 2). Develop the following methods for this class:
currentBook
that checks whether the book was
published in 2003 or 2002;
currentAuthor
that determines whether a book was written by
a current author (born after 1940);
thisAuthor
that determines whether a book was written by the
specified author;
sameAuthor
that ddetermines whether one book was written by
the same author as some other book;
sameGeneration
that determines whether two books were
written by two authors born less than 10 year
apart. Solution
Exercise 2 provides the data definition for a weather recording program. Develop the following methods:
withinRange
that determines whether today's high
and low
were within the normal range;
rainyDay
that determines whether the precipitation is
higher than some given value;
recordDay
that determines whether the temperature broke
either the high or the low record;
warmerThan
that determines whether one day was wormer than
another day;
lowerRecord
that determines whether the record low for one
day was lower than for some other day. Solution