-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBook.java
43 lines (35 loc) · 986 Bytes
/
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
import java.util.HashMap;
// Book class
public class Book {
private String bookId;
private String title;
private boolean isAvailable;
// Constructor
public Book(String bookId, String title) {
this.bookId = bookId;
this.title = title;
this.isAvailable = true;
}
// Getters
public String getBookId() {
return bookId;
}
public String getTitle() {
return title;
}
public boolean isAvailable() {
return isAvailable;
}
// Borrow book
public void borrowBook() {
if (isAvailable) {
isAvailable = false;
} else {
System.out.println("Book is already borrowed.");
}
}
// Return book
public void returnBook() {
isAvailable = true;
}
}