-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.java
88 lines (65 loc) · 1.97 KB
/
Book.java
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
/** This class hold information about book object.
which also implements comparable interface.
* @author b1014963 , Abdul Al-FARAJ
* @Date 17/10/2012
*/
public class Book implements Comparable<Book> {
/* Declaring all members of book**/
private String bookTitle, authorFirst, authoerSurname;
private boolean borrowed;
private User theBorrower;
public Book ()
{
bookTitle= authorFirst = authoerSurname = null;
borrowed=false;
}
public Book (String title, String first,String surname)
{
bookTitle=title;
authorFirst=first;
authoerSurname=surname;
borrowed=false;
/** I assume that the books are initially not borrowed, because they are new to the library */
}
// The following methods is to get the members, and because we get our members from a file,
// I do not make any set methods for the members.
// The only set method, created, is for 'borrowed/borrower', for future changes when users borrow a book.
public String getAuthorName(){ // return surname first
String temp = getSurname() + ", " +getFirstName() ;
return temp;
}
public String getFirstName(){
return authorFirst;
}
public String getSurname(){
return authoerSurname;
}
public String getBookTitle(){
return bookTitle;
}
public void setBorrowed(boolean state){
borrowed=state;
}
public boolean isBorrowed(){
return borrowed;
}
@Override
public int compareTo(Book obj){
return this.authoerSurname.compareTo(obj.authoerSurname);
// The above statements compare the two surnames lexicographically and send 1,-1, or 0 accordingly.
}
@Override
public String toString()
{
return "\nTitle: " + this.getBookTitle()+ "\nAuthor: "+ this.getAuthorName() + "\nBorrowed\f: "+ isBorrowed()
+"\n------------------------------------------------";
}
public void setTheBorrower(User usr)
{
theBorrower= usr;
}
public User getTheBorrower()
{
return theBorrower;
}
}