Design methods, build a test suite, introduction to templates
(9.1.2, 9.1.3, 9.1,4, 9.1.5)
Draw the complete diagram for
Coffee
with all the method
signatures included in the method compartment. SolutionRemember the class
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. Solution
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. Solution
Here is a revision of the problem of managing a runner's log (see figure fig:entry):
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. Solution