-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBookList.java
159 lines (137 loc) · 4.83 KB
/
BookList.java
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.io.*;
import java.util.*;
class BookList
{
String isbn,name,details;
boolean isAvailable, isTaken;
BookList(){
isAvailable = false;
isTaken = true;
}
BookList(String isbn, String name, String details, boolean isAvailable, boolean isTaken)
{
this.isbn = isbn;
this.name = name;
this.details = details;
this.isAvailable = isAvailable;
this.isTaken = isTaken;
}
protected void loadBooks()throws IOException
{
BookList book1 = new BookList("12345678901","JAVA", "Introduction to JAVA", true, false);
BookList book2 = new BookList("12567890134","CPP", "Introduction to C++", true, false);
BookList book3 = new BookList("23456789011","Python", "Introduction to Python", true, false);
BookList book4 = new BookList("13456789012","WebDev", "Introduction to Web Development", true, false);
BookList book5 = new BookList("12456789013","Python", "Introduction to Python", true, false);
System.out.println("Name : " + book1.name);
System.out.println("ISBN : " + book1.isbn);
System.out.println("Details : " + book1.details);
System.out.println("Available : " + !book1.isTaken);
System.out.println();
System.out.println("Name : " + book2.name);
System.out.println("ISBN : " + book2.isbn);
System.out.println("Details : " + book2.details);
System.out.println("Available : " + !book2.isTaken);
System.out.println();
System.out.println("Name : " + book3.name);
System.out.println("ISBN : " + book3.isbn);
System.out.println("Details : " + book3.details);
System.out.println("Available : " + !book3.isTaken);
System.out.println();
System.out.println("Name : " + book4.name);
System.out.println("ISBN : " + book4.isbn);
System.out.println("Details : " + book4.details);
System.out.println("Available : " + !book4.isTaken);
System.out.println();
System.out.println("Name : " + book5.name);
System.out.println("ISBN : " + book5.isbn);
System.out.println("Details : " + book5.details);
System.out.println("Available : " + book5.isTaken);
System.out.println();
}
protected void issueBook(String regnum, String isbn_num)throws IOException
{
String reg[] = new String[100];
reg[0] = "18BIT0251";
reg[1] = "18BIT0239";
reg[2]="18BME0827";
String book_isbn[] = new String[100];
book_isbn[0] = "12456789013";
book_isbn[1] = "13456789012";
book_isbn[2] = "12567890134";
//Adding the new record ot the list
int num_reg = 3;
reg[num_reg] = regnum;
book_isbn[num_reg] = isbn_num;
num_reg++;
System.out.println("Book issued successfully!");
}
protected void returnBook(String regnum)throws IOException
{
String reg[] = new String[100];
reg[0] = "18BIT0251";
reg[1] = "18BIT0239";
reg[2]="18BME0827";
String book_isbn[] = new String[100];
book_isbn[0] = "12456789013";
book_isbn[1] = "13456789012";
book_isbn[2] = "12567890134";
int num_reg = 3;
for (int i = 0;i<num_reg;i++)
{
if (reg[i]==regnum)
{
reg[i]= "NA";
book_isbn[i]="NA";
}
}
System.out.println("Deleted Successfully");
}
protected void addWaitingBook(String regnum, String isbn_num)throws IOException
{
String waiting_isbn[] = new String[100];
String waiting[][] = new String[100][5];
int num_wait = 1;
waiting_isbn[0] = "13456789012";
waiting[0][0] = "18BME0827";
waiting[0][1] = "NA";
waiting[0][2] = "NA";
waiting[0][3] = "NA";
waiting[0][4] = "NA";
boolean flag = false;
int pos = -1;
for (int i = 0;i<num_wait;i++)
{
if (waiting_isbn[i]==isbn_num)
{
flag = true;
pos = i;
break;
}
}
boolean flag2 = false;
if (flag == true)
{
for (int j = 0;j<5;j++)
{
if (waiting[pos][j] == "NA")
{
waiting[pos][j] = regnum;
flag2 = true;
break;
}
}
if (flag == true)
System.out.println("Book waitlisted successfully!");
else
System.out.println("Waiting List full, try again later!");
}
else
{
waiting_isbn[num_wait] = isbn_num;
waiting[num_wait][0] = regnum;
num_wait++;
System.out.println("Book waitlisted successfully");
}
}
}