4.5  Example: Determine which of two books has been published earlier

1. Data Analysis and Problem Analysis

We need two books - this book which invokes the method and that book which will be the argument for the method.

2. Purpose and Contract/Header:

  // determine whether this book was published before that book
  boolean olderThan(Book that){...}

3. Examples:

  b1.olderThan(b2)  -- expected: false
  b2.olderThan(b1)  -- expected: true

4. Template:

We need to add to the basic template the fields of that book.

  boolean olderThan(Book that){...}
    ... this.title ...   ... that.title ...
    ... this.author ...  ... that.title ...
    ... this.price ...   ... that.title ...
    ... this.year ...    ... that.title ...
  }

5. Program:

  boolean olderThan(Book that){...}
   return this.year < that.year;
  }

6. Tests:

  b1.olderThan(b2) == false
  b2.olderThan(b1) == true