-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
64 lines (50 loc) · 1.36 KB
/
Copy pathBook.java
File metadata and controls
64 lines (50 loc) · 1.36 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 {
static int totalNoOfBook;
String title;
String author;
String isbn;
boolean isBorrowed;
static {
totalNoOfBook = 0;
}
{ // Object Init
totalNoOfBook++;
}
Book(String isbn, String author, String title) {
this.isbn = isbn;
this.author = author;
this.title = title;
}
Book(String isbn) {
this(isbn, "Unknown", "Unknown");
}
static int getTotalNoOfBooks() {
return totalNoOfBook;
}
void borrowBook() {
if (isBorrowed) {
System.out.println("Book is already borrowed");
} else {
this.isBorrowed = true;
System.out.println("Enjoy " + this.title);
}
}
void returnBook() {
if (isBorrowed) {
this.isBorrowed = false;
System.out.println("Hope you enjoyed the book");
} else {
System.out.println("This book is already in library");
}
}
public static void main(String[] args) {
Book designOfThings = new Book("1", "Author", "Design");
Book myBook = new Book("2");
System.out.println(Book.getTotalNoOfBooks());
designOfThings.borrowBook();
myBook.borrowBook();
designOfThings.borrowBook();
designOfThings.returnBook();
designOfThings.returnBook();
}
}