-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathBook.java
More file actions
54 lines (49 loc) · 1.25 KB
/
Book.java
File metadata and controls
54 lines (49 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package examplesUsingMainClass;
import tester.ISame;
/**
* A class to represent a book with an author.
* An example of a class with containment.
*/
public class Book implements ISame<Book> {
/** the title of the book */
public String title;
/** the author of the book - an instance of
* <CODE>{@link Author Author}</CODE> class */
protected Author author;
/** the year of publication */
protected int year;
/**
* Constructor
*
* @param title the tile of the book
* @param author the author of the book
* @param year the year of publication
*/
public Book(String title, Author author, int year) {
this.title=title;
this.author=author;
this.year=year;
}
/**
* Method to use in tests - change the
* <CODE>{@link Author Author}</CODE> of this book to the given one.
*
* @param auth the given author
* @return new book with real author as given
*/
public Book changeAuthor(Author auth) {
return new Book(this.title, auth, this.year);
}
/**
* Is this book the same as that book?
*
* @param that the book to compare with
* @return true if this book is the same as that book
*/
public boolean same(Book that) {
return
this.title.equals(that.title) &&
this.author.same(that.author) &&
this.year == that.year;
}
}