-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDigitalLibraryManagement.java
403 lines (384 loc) · 17.1 KB
/
DigitalLibraryManagement.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
import java.util.*;
class DigitalLibraryManagement{
HashMap<String,Integer> loginto = new HashMap<>();
HashMap<Integer,String> map = new HashMap<>();
public static String userID;
public static int issues = 0;
Scanner sc=new Scanner(System.in);
public HashMap<Integer,String> book_database_server()
{
map.put(1,"EE : Electric Machine-1");
map.put(2,"EE : Electric Machine-2");
map.put(3,"EE : Electric Drive");
map.put(4,"EE : Power System-1");
map.put(5,"EE : Power System-2");
map.put(6,"EE : Basic Electrical");
map.put(7,"EE : Power Electronics");
map.put(8,"ECE : Basic Electronics");
map.put(9,"ECE : Microprocessor & Microcontroller");
map.put(10,"ECE : Analog Electronics");
map.put(11,"ECE : Digital Electronics");
map.put(12,"CSE : C Programming");
map.put(13,"CSE : Java Programming");
map.put(14,"CSE : Artificial Intelligence");
map.put(15,"CSE : Object Oriented Programming (OOPs)");
map.put(16,"IT : Data Structures & Algorithms");
map.put(17,"IT : Databases - Networks");
map.put(18,"IT : Statistics");
map.put(19,"BBA : Principle of Management");
map.put(20,"BBA : Economics for Engineers");
map.put(21,"MATHS : Engineering Mathematics-1");
map.put(22,"MATHS : Engineering Mathematics-2");
map.put(23,"MATHS : Engineering Mathematics-3");
map.put(24,"PHYS : Physics");
map.put(25,"CHEM : Chemistry");
map.put(26,"ENG : English");
map.put(27,"BENG : Bengali");
map.put(28,"HIND : Hindi");
map.put(29,"EE : Control System");
map.put(30,"EE : Electrical Circuit Theory");
map.put(31,"EE : Electric & Hybrid Vehicle");
map.put(32,"EE : Renewable Energy Sources");
return map;
}
public void homepage()
{
System.out.println("--------------------------------------------------------");
System.out.println("----- WELCOME TO DIGITAL LIBRARY MANAGEMENT SYSTEM -----");
System.out.println("----------------------- HOMEPAGE -----------------------");
System.out.println("--------------------------------------------------------");
System.out.println("Please Select One Option..." + "\n");
System.out.println("1.>>> Admin Login >>>");
System.out.println("2.>>> User Login >>>");
System.out.println("3.>>> Exit >>>");
System.out.println("--------------------------------------------------------");
System.out.print("Select Option: ");
int sp=sc.nextInt();
switch(sp){
case 1:
admin_login();
break;
case 2:
user_login();
break;
case 3:
System.out.print("\n" + "Do You want to Exit? (Y/N): ");
String exit = sc.next();
if(exit.equalsIgnoreCase("Y"))
{
System.out.println("\n" + "--------------------------------------------------------");
System.out.println("\n" + "EXITING SUCCESSFULLY...!");
System.out.println("\n" + "--------------------------------------------------------");
System.out.println("\n" + "Thank You.!!! Please Visit Again...");
System.out.println("\n" + "--------------------------------------------------------");
System.exit(0);
}
else{
System.out.println("\n" + "Exiting Cancelled... Stayed on the HomePage...");
homepage();
}
break;
default:
System.out.println("\n" + "Invalid Option Choice.! Please Try again...");
homepage();
break;
}
}
public void admin_login()
{
System.out.println("--------------------------------------------------------");
System.out.println("------------------- ADMIN LOGIN PAGE -------------------");
System.out.println("--------------------------------------------------------");
System.out.print("Enter User-Id: ");
userID = sc.next();
System.out.print("Enter Password: ");
int password = sc.nextInt();
loginto.put("Soumya",13579);
loginto.put("Soumyadip",20026);
if (loginto.containsKey(userID) && loginto.get(userID) == password)
{
System.out.println("--------------------------------------------------------");
System.out.println("\n" + "LOGIN SUCCESSFULLY...!");
System.out.println("\n" + "--------------------------------------------------------");
admin_mainpage();
}
else{
System.out.println("\n" + "Invalid login credentials.!!! Please try again...");
admin_login();
}
}
public void user_login()
{
System.out.println("--------------------------------------------------------");
System.out.println("-------------------- USER LOGIN PAGE -------------------");
System.out.println("--------------------------------------------------------");
System.out.print("Enter User-Id: ");
userID = sc.next();
System.out.print("Enter Password: ");
int password = sc.nextInt();
loginto.put("Soumya",13579);
loginto.put("Soumyadip",20026);
loginto.put("Soumy",12345);
loginto.put("SPal",24680);
loginto.put("Dip",11111);
if (loginto.containsKey(userID) && loginto.get(userID) == password)
{
System.out.println("--------------------------------------------------------");
System.out.println("\n" + "LOGIN SUCCESSFULLY...!");
System.out.println("\n" + "--------------------------------------------------------");
user_mainpage();
}
else{
System.out.println("\n" + "Invalid login credentials.!!! Please try again...");
user_login();
}
}
public void admin_mainpage()
{
System.out.println("--------------------------------------------------------");
System.out.println("----- Digital Library ---> Welcome Admin " + DigitalLibraryManagement.userID + "! ----");
System.out.println("-------------------- ADMIN MAINPAGE --------------------");
System.out.println("--------------------------------------------------------");
System.out.println("Please Select One Option..." + "\n");
System.out.println("1.>>> Add a New Book >>>");
System.out.println("2.>>> Update a Existing Book >>>");
System.out.println("3.>>> Delete a Existing Book >>>");
System.out.println("4.>>> Go To User MainPage >>>");
System.out.println("5.>>> Logout >>> Back to HomePage >>>");
System.out.println("--------------------------------------------------------");
System.out.print("Select Option: ");
int sp=sc.nextInt();
switch(sp){
case 1:
map = add_new();
admin_mainpage();
break;
case 2:
map = upd_old();
admin_mainpage();
break;
case 3:
map = del_old();
admin_mainpage();
break;
case 4:
user_mainpage();
break;
case 5:
System.out.println("--------------------------------------------------------");
System.out.println("\n" + "LOGOUT SUCCESSFULLY...!");
System.out.println("\n" + "--------------------------------------------------------");
homepage();
break;
default:
System.out.println("\n" + "Invalid Option Choice.! Please Try again...");
admin_mainpage();
break;
}
}
public void user_mainpage()
{
System.out.println("--------------------------------------------------------");
System.out.println("----- Digital Library ---> Welcome User " + DigitalLibraryManagement.userID + "! -----");
System.out.println("--------------------- USER MAINPAGE --------------------");
System.out.println("--------------------------------------------------------");
System.out.println("Please Select One Option..." + "\n");
System.out.println("1.>>> View any Book >>>");
System.out.println("2.>>> Issue a Book >>>");
System.out.println("3.>>> Return a Book >>>");
System.out.println("4.>>> Logout >>> Back to HomePage >>>");
System.out.println("--------------------------------------------------------");
System.out.print("Select Option: ");
int sp=sc.nextInt();
switch(sp){
case 1:
views();
break;
case 2:
borrows();
break;
case 3:
returns();
break;
case 4:
System.out.println("--------------------------------------------------------");
System.out.println("\n" + "LOGOUT SUCCESSFULLY...!");
System.out.println("\n" + "--------------------------------------------------------");
homepage();
break;
default:
System.out.println("\n" + "Invalid Option Choice.! Please Try again...");
user_mainpage();
break;
}
}
public HashMap<Integer,String> add_new()
{
Scanner scanner = new Scanner(System.in);
System.out.println("--------------------- ADD A NEW BOOK -------------------");
System.out.print("Enter a New Book Number: ");
int addbook = sc.nextInt();
if(book_database_server().containsKey(addbook))
{
System.out.println("\n" + "This Book Number is already exist... Please try with another number...");
}
else if(addbook == 0 || addbook < 0)
{
System.out.println("\n" + "You can't assign Zero(0) or a Negative(-ve) number for a book...");
}
else{
System.out.print("Enter New Book Details: ");
String addbookdetails = scanner.nextLine();
map.put(addbook,addbookdetails);
System.out.println("\n" + "New Book added Successfully...");
System.out.println("New Book No.:: " + addbook);
System.out.println("New Book Name & Details:: " + map.get(addbook));
}
return map;
}
public HashMap<Integer,String> upd_old()
{
Scanner scan = new Scanner(System.in);
System.out.println("----------------- UPDATE A BOOK DETAILS ----------------");
System.out.print("Enter a Book No. to Update its Details: ");
int updbook = sc.nextInt();
if(book_database_server().containsKey(updbook))
{
System.out.println("Backdated Book Name & Details:: " + map.get(updbook));
System.out.print("Enter the Updated Book Details: ");
String upbookdetails = scan.nextLine();
book_database_server().replace(updbook,upbookdetails);
System.out.println("\n" + "Book Details Updated Successfully...!");
System.out.println("Book No.:: " + updbook);
System .out.println("Updated Book Name & Details:: " + map.get(updbook));
}
else{
System.out.println("\n" + "This Book Number is not Available...!");
}
return map;
}
public HashMap<Integer,String> del_old()
{
System.out.println("----------------- DELETE A BOOK DETAILS ----------------");
System.out.print("Enter the Book Number, which you want to delete: ");
int delbook = sc.nextInt();
if(book_database_server().containsKey(delbook))
{
System.out.println("\n" + "Book Details You Want to Delete...>>>");
System.out.println("Book No.:: " + delbook);
System .out.println("Book Name:: " + map.get(delbook));
System.out.print("\n" + "Do You want to Delete this Book? (Y/N): ");
String delbookdetails = sc.next();
if(delbookdetails.equalsIgnoreCase("Y"))
{
String returned_value = (String)map.remove(delbook);
System.out.println("\n\"" + returned_value + "\" Book Details Deleted Successfully...");
}
else{
System.out.println("\n" + "Book Deletion Cancelled...!");
}
}
else{
System.out.println("\n" + "This Book Number Already not Exists.!!!");
}
return map;
}
public void views()
{
System.out.println("--------------------------------------------------------");
System.out.println("---------------------- VIEW BOOKS ----------------------");
System.out.println("--------------------------------------------------------");
System.out.println("Please Select One Option..." + "\n");
System.out.println("1.>>> View a Specific Book >>>");
System.out.println("2.>>> View all Books >>>");
System.out.println("3.>>> Back to MainPage >>>");
System.out.println("--------------------------------------------------------");
System.out.print("Select Option: ");
int dip=sc.nextInt();
switch(dip){
case 1:
System.out.println("--------------------------------------------------------");
System.out.print("Enter Book Number: ");
int books = sc.nextInt();
if(book_database_server().containsKey(books))
{
System.out.println("\n" + books + " ---> " + map.get(books));
}
else{
System.out.println("\n" + "Oops.! This book no. is not available... Please Try Another...");
}
views();
break;
case 2:
System.out.println("\n" + "All Available Books...>>>" + "\n");
for(Map.Entry<Integer, String> entry : book_database_server().entrySet())
{
int key = entry.getKey();
String value = entry.getValue();
System.out.println(key + " ---> " + value);
}
views();
break;
case 3:
System.out.println("--------------------------------------------------------");
System.out.println("\n" + "REDIRECTING TO USER MAINPAGE..." + "\n");
System.out.println("--------------------------------------------------------");
user_mainpage();
break;
default:
System.out.println("\n" + "Invalid Option Choice.! Please Try again...");
views();
break;
}
}
public void borrows()
{
System.out.println("--------------------- ISSUE A BOOK ---------------------");
System.out.print("Enter a Book Number which You want to Issue: ");
int isbook = sc.nextInt();
if(issues == 0 && isbook > 0 && book_database_server().containsKey(isbook))
{
issues = isbook;
System.out.println("\n" + "Successfully Issued the Book...");
System.out.println("Issued Book No.:: " + isbook);
System .out.println("Issued Book Name & Details:: " + map.get(isbook));
}
else if(issues != 0)
{
System.out.println("\n" + "You have Already Issued a Book.! Please Return that book to Issue a new book...");
}
else
{
System.out.println("\n" + "Invalid Book Number or Book is not Available...");
}
user_mainpage();
}
public void returns()
{
System.out.println("--------------------- RETURN A BOOK --------------------");
if(book_database_server().containsKey(issues))
{
System.out.println("Issued Book Details...>>>");
System.out.println("Book No.:: " + issues);
System .out.println("Book Name:: " + map.get(issues));
System.out.print("\n" + "Do You want to Return this Book? (Y/N): ");
String rebook = sc.next();
if(rebook.equalsIgnoreCase("Y"))
{
issues = 0;
System.out.println("\n" + "Book Returned Successfully...");
}
else{
System.out.println("\n" + "Book Return Cancelled...!");
}
}
else{
System.out.println("\n" + "You don't have any issued book.!!!");
}
user_mainpage();
}
public static void main(String args[]){
DigitalLibraryManagement system_run = new DigitalLibraryManagement();
system_run.homepage();
}
}