-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
45 lines (38 loc) · 1.08 KB
/
Copy pathBook.java
File metadata and controls
45 lines (38 loc) · 1.08 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
public non-sealed class Book implements MediaItem, Borrowable{
private String title;
private String author;
private String isbn;
private boolean available = true;
private String borrowedBy;
public Book(String title, String author, String isbn){
this.title= title;
this.author=author;
this.isbn = isbn;
}
public String getTitle(){
return title;
}
public void borrow(String user){
if (available){
available = false;
borrowedBy = user;
System.out.println(user + " borrowed " + title);
} else{
System.out.println("Item is not available, already borrowed by " + borrowedBy);
}
}
public void returnItem(){
if(!available){
available = true;
System.out.println(title + " returned by " + borrowedBy);
borrowedBy = null;
}
}
public boolean isAvailable(){
return available;
}
@Override
public String toString() {
return "Book: " + title + " | Author: " + author;
}
}