The problem deals with two books - this book and that book.
// determine whether this book was written by an earlier author // than that book boolean earlier(Book that) { ... }
Author mf = new Author("Matthias", 1900); Author pc = new Author("Pat Conroy", 1940); Book b1 = new Book("HtDP", mf, 60, 2001); Book b2 = new Book("Beach Music", pc, 20, 1996); ... b1.earlier(b2) -- expected: true b2.earlier(b1) -- expected: false
The template includes the field selectors for both this book and for that book, as well as the field selectors for the respective authors.
boolean earlier(Book that) { ... } ... this.title ... ... that.title ... ... this.author ... ... that.author ... ... this.author.name ... ... that.author.name ... ... this.author.dob ... ... that.author.dob ... ... this.price ... ... that.price ... ... this.year ... ... that.year ... }
// determine whether this book was written by an earlier author // than that book boolean earlier(Book that) { return this.author.dob < that.author.dob; }
b1.earlier(b2) == true b2.earlier(b1) == false