4.4  Example: Determine whether a book costs less than the given amount

1. Data Analysis and Problem Analysis

The book in question invokes the method. The only additional information needed is the desired amount. We expect it to be an integer.

2. Purpose and Contract/Header:

  // determine whether this book is cheaper than the given amount
  boolean cheaperThan(int amount){...}

3. Examples:

  b1.cheaperThan(100)  -- expected: true
  b2.cheaperThan(10)   -- expected: false

4. Template:

  boolean cheaperThan(int amount){...}
    ... this.title ...
    ... this.author ...
    ... this.price ...
    ... this.year ...
  }

5. Program:

  boolean cheaperThan(int amount){
    return this.price < amount;
  }

6. Tests:

  b1.cheaperThan(100) == true
  b2.cheaperThan(10)  == false