4  Lab Tuesday pm:

Design methods, build a test suite, introduction to templates

Methods for simple classes and classes with containment

(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. Solution

Remember the class Image from exercise 2 for creating Web pages. Develop the following methods for this class:
  1. isPortrait, which determines whether the image is taller than wider;

  2. size, which computes how many pixels the image contains;

  3. 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:
  1. isBigger, which determines whether one house has more rooms than some other house;

  2. thisCity, which checks whether the advertised house is in some given city (assume we give the method a city name);

  3. 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