-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBook.java
More file actions
63 lines (52 loc) · 1.44 KB
/
Copy pathBook.java
File metadata and controls
63 lines (52 loc) · 1.44 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
import java.util.Scanner;
public class Book {
static int totalNoOfBooks;
String author;
String title;
String isbn;
boolean isBorrowed;
static {
totalNoOfBooks = 0;
}
{ //Object Init
totalNoOfBooks++;
}
Book(String isbn,String title,String author) {
this.isbn = isbn;
this.title = title;
this.author = author;
this.isBorrowed = false;
}
Book(String isbn) {
this(isbn,"Unknown","Unknown");
}
static int getTotalNoOfBooks() {
return totalNoOfBooks;
}
void borrowedBook() {
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,Please leave a review");
} else {
System.out.println("This book is already in the library");
}
}
public static void main(String[] args) {
Book designOfThings = new Book("1","Design","Author");
Book myBook = new Book("2");
System.out.println(Book.getTotalNoOfBooks());
designOfThings.borrowBook();
myBook.borrowBook();
designOfThings.borrowBook();
designOfThings.returnBook();
designOfThings.returnBook();
}
}