/** * This class represents a book in a bookstore with title, * author and the year of publication. */ class Book{ /** the title of this book */ private String title; /** the author of this book */ private String author; /** the year this book was published */ private int year; /** * The full constructor * @param title book title * @param author book author * @param year publication year */ public Book(String title, String author, int year){ this.title = title; this.author = author; if (year >= 1900 && year <= 2008) this.year = year; else this.year = 2008; } /* TEMPLATE: FIELDS: ... this.title ... -- String ... this.author ... -- String ... this.year ... -- int METHODS FOR FIELDS: ... this.name.equals(String) ... -- boolean ... this.author.equals(String) ... -- boolean METHODS FOR THIS CLASS: ... this.same(Book) ... -- boolean */ /** * Is this book the same as the given one? * @param that the given book * @return true if the books are the same */ public boolean same(Book that){ return this.title.equals(that.title) && this.author.equals(that.author) && this.year == that.year; } // getters and setters public String getTitle(){ return this.title; } public String getAuthor(){ return this.author; } public int getYear(){ return this.year; } public void setTitle(String title){ this.title = title; } public void setAuthor(String author){ this.author = author; } public void setYear(int year){ if (year >= 1900 && year <= 2008) this.year = year; else this.year = 2008; } }