Design methods, build a test suite, introduction to templates
Image from exercise 2 for
creating Web pages. Develop the following methods for this class:
isPortrait, which determines whether the image is taller
than wider;
size, which computes how many pixels the image contains;
isLarger, which determines whether one image contains more
picture than some other image.
Develop the following methods for the class
House from
exercise 2:
isBigger, which determines whether one house has more rooms
than some other house;
thisCity, which checks whether the advertised house is in
some given city (assume we give the method a city name);
sameCity, which determines whether one house is in the same
city as some other house.
Don't forget to test these methods.
Here is a revision of the problem of managing a runner's log (see figure 4):
Develop a program that manages a runner's training log. Every day the runner enters one entry concerning the day's run. ...For each entry, the program should compute how fast the runner ran. ...Develop a method that computes the pace for a daily entry.
+-----------------+ | Entry | +-----------------+ +-----------+ | Date d |-->| Date | | double distance | +-----------+ | int duration | | int day | | String comment | | int month | +-----------------+ | int year | +-----------+
Figure: An entry for a runner's log
Methods for composition
Note: The classes for the exercise 4 are in your handouts. Add the methods to these classes.
Recall the problem of writing a program that assists a book store manager (see exercise 2). Develop the following methods for this class:
currentBookthat checks whether the book was published in 2003 or 2002;
currentAuthorthat determines whether a book was written by a current author (born after 1940);
thisAuthorthat determines whether a book was written by the specified author;
sameAuthorthat determines whether one book was written by the same author as some other book;
sameGenerationthat determines whether two books were written by two authors born less than 10 year apart.
Exercise 2 provides the data definition for a program that keep track of weather records. Develop the following methods:
withinRangethat determines whether today'shighandlowtemperatures were within the normal range;
rainyDaythat determines whether the precipitation is higher than some given value;
recordDaythat determines whether the temperature broke either the high or the low record;
warmerThanthat determines whether one day was wormer than another day;
lowerRecordthat determines whether the record low for one day was lower than for some other day.