-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBook.java
More file actions
64 lines (53 loc) · 1.83 KB
/
Copy pathBook.java
File metadata and controls
64 lines (53 loc) · 1.83 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
public class Book{
// Private member variables to store the book's title, author, and borrowed status.
private String title;
private String author;
private boolean isBorrowed;
// Constructor to initialize
public Book(String title, String author){
this.title = title;
this.author = author;
this.isBorrowed = false;
}
// Method to borrow a book.
public void borrowBook() {
// To check if the book is not already borrowed.
if(!isBorrowed){
isBorrowed = true;
System.out.println("Book is successfully borrowed: " + title);
} else{
System.out.println("Sorry, this book is already borrowed");
}
}
// Method to return a book.
public void returnBook() {
// To check if the book is already borrowed.
if(isBorrowed){
isBorrowed = false;
System.out.println("You've successfully returned the book: " + title);
} else {
// If the book wasn't borrowed, display a message.
System.out.println("This book wasn't borrowed");
}
}
// Method to check if the book is available (not borrowed).
public boolean isAvailable() {
return !isBorrowed;
}
// Getter method to retrieve to book's title.
public String getTitle(){
return title;
}
// Getter method to retrieve the book's author.
public String getAuthor(){
return author;
}
// Getter method to check if the book is borrowed.
public boolean isBorrowed(){
return isBorrowed;
}
//Method to diaplay the book's details.
public void displayDetails() {
System.out.println("Title: " + title + ", Author: " + author);
}
}