-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
57 lines (49 loc) · 1.38 KB
/
Book.java
File metadata and controls
57 lines (49 loc) · 1.38 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
public class Book {
static int totalNoOfBooks;
String author;
String title;
String isbn;
boolean isBorrowed;
static {
totalNoOfBooks=0;
}
{//object initialisation
totalNoOfBooks++;
}
Book(String isbn,String title,String author){
this.isbn =isbn;
this.title =title;
this.author = author;
}
Book(String isbn){
this(isbn,"Unknown","Unknown");
}
static int getTotalNoOfBooks(){
return totalNoOfBooks;
}
void borrowBook(){
if(isBorrowed){
System.out.println("Book is already Borrowed");
}else {
this.isBorrowed = true;
System.out.println("Enjoy the book");
}
}
void returnBook(){
if(isBorrowed){
this.isBorrowed=false;
System.out.println("Hope you enjoyed, please leave a review");
}else{
System.out.println("This book is already in th library");
}
}
public static void main(String[] args) {
Book designOfThings=new Book("01","Design","Author");
Book mybook =new Book("02");
System.out.println(Book.getTotalNoOfBooks());
designOfThings.borrowBook();
mybook.borrowBook();
designOfThings.borrowBook();
designOfThings.returnBook();
}
}