-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
110 lines (91 loc) · 2.35 KB
/
Book.java
File metadata and controls
110 lines (91 loc) · 2.35 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* Book.java
*/
import java.util.Date;
public class Book{
public static final int AVAILABLE = 1;
public static final int UNAVAILABLE = 2;
private String title;
private String author;
private String isbn;
private int pages;
private int year;
private int status;
private Date due;
private Patron patron;
public void Book(String title, String author, String isbn, int year, int pages) {
this.title = title;
this.author = author;
this.isbn = isbn;
this.year = year;
this.pages = pages;
}
// Like the constructor, the checkin method should set the book's status to AVAILABLE
// and assign null to both patron and due date.
public void checkin() {
status = AVAILABLE;
due = null;
patron = null;
}
// The checkout method should make the book UNAVAILABLE and
//save the given patron and due date in the object
public void checkout(Patron patron, Date due) {
status = UNAVAILABLE;
this.patron = patron;
this.due = due;
}
// The equals method checks whether two books have the same isbn.
// If the given object is a Book, compare this.isbn with the other book's isbn.
// If the given object is a String, compare this.isbn with the string
public boolean equals(Object other) {
if (other instanceof Book) {
if (this.isbn.equals(isbn)) {
return true;
}
else {
return false;
}
}
else if (other instanceof String) {
if (this.isbn.equals(other)) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
// In the UML diagram, getX is actually eight methods:
// one accessir method for each of the eight attributes
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getIsbn() {
return isbn;
}
public int getYear() {
return year;
}
public int getPages() {
return pages;
}
public int getStatus() {
return status;
}
public Patron getPatron() {
return patron;
}
public Date getDue() {
return due;
}
// The toString method should return a String representation of the book
public String toString() {
return String.format("Title: %s Author: " + author + ", ISBN: " + isbn + ", Year: " + year + ", Pages: " + pages + ".");
}
}