-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookLibrary.java
More file actions
64 lines (56 loc) · 1.61 KB
/
BookLibrary.java
File metadata and controls
64 lines (56 loc) · 1.61 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
class Book {
String title;
String author;
String isbn;
static int totalnoofbook;
boolean isborrowed;
static {
totalnoofbook = 0;
}
{
totalnoofbook++;
isborrowed = false;
}
Book(String isbn, String title, String author) {
this.isbn = isbn;
this.author = author;
this.title = title;
}
Book(String isbn) {
this(isbn, "Unknown", "Unknown");
}
static int getTotalNOBook() {
return totalnoofbook;
}
void borrowBook() {
if (isborrowed) {
System.out.println("Book is already borrowed! name as "+this.title);
} else {
this.isborrowed = true;
System.out.println("Enjoy "+this.title);
}
}
void returnBook() {
if (isborrowed) {
this.isborrowed = false;
System.out.println("Hope you enjoyed it! name as "+this.title);
} else {
System.out.println("Book already returned! name as "+this.title);
}
}
}
public class BookLibrary {
public static void main(String[] args) {
Book design = new Book("xxxxxx21874");
Book designOfBooks = new Book("xxxxxx985454", "Student Life", "Aditya Devraj");
System.out.println(Book.getTotalNOBook());
designOfBooks.borrowBook();
design.borrowBook();
designOfBooks.borrowBook();
designOfBooks.returnBook();
designOfBooks.returnBook();
design.borrowBook();
design.returnBook();
design.returnBook();
}
}