├── Project_review.pdf ├── README.md ├── Results in snapshots.docx ├── append.txt ├── library_management.java ├── x.txt ├── y.txt └── z.txt /Project_review.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajvi-patel-22/Library-Management-System-Searching-catalogues-in-library-using-binary-search-tree/4db6fba527087729678c0919bb4d26c67a9f737e/Project_review.pdf -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Library-Management-System-Searching-catalogues-in-library-using-binary-search-tree 2 | Our main objective in this project is to create a library management system wherein students can issue books and the admin or librarian can update/delete the record of books kept in the library. So we have the system into two parts : from user’s perspective and from admin’s perspective. First of all, the admin must login to handle the accounts where the username and password are already set. After he has logged in successfully, he can add, delete and update the books. He can add any new book in the already existing list of books. Similarly he can also delete any existing book. In the update option, the admin can update the quantity of books as well as the name of the book. As and when the admin adds the books, a binary search tree will be created where the nodes contain the name of books and are put in sorted order. Now if a student wants to issue/return any book, then he/she must login into the system, by enetering their valid university ID. The student will be allowed to issue/return only if their ID matches the list of university ID’s of students. When the student enters the name of book to be issued, that particular book will be searched by it’s name, in the already created binary search tree. If the book is not found in the tree, then a message will be printed “Book is not available in the library”. And if the book is out of stock, then this message will be printed, “This book is currently unavailable. Please try after some days.” Moreover, the student cannot issue more than 2 books simultaneously. When the student issues a book, the issuing date and time is recorded by the librarian. And if the student misses the due date of returning the book, then he has to pay that particular fine. 3 | -------------------------------------------------------------------------------- /Results in snapshots.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rajvi-patel-22/Library-Management-System-Searching-catalogues-in-library-using-binary-search-tree/4db6fba527087729678c0919bb4d26c67a9f737e/Results in snapshots.docx -------------------------------------------------------------------------------- /append.txt: -------------------------------------------------------------------------------- 1 | 2 | Student name: Rajvi 3 | Student ID : 1741078 4 | Issued Book : dsa 5 | Issued date : 30/10/2018 12:34:58 6 | Return date : 30/10/2018 12:35:03 7 | 8 | Student name: Kalagee 9 | Student ID : 1741052 10 | Issued Book : la 11 | Issued date : 30/10/2018 12:35:03 12 | Return date : 30/10/2018 12:35:08 13 | 14 | Student name: Rajvi 15 | Student ID : 1741078 16 | Issued Book : co 17 | Issued date : 30/10/2018 12:35:08 18 | Return date : 30/10/2018 12:35:13 19 | 20 | Student name: Krushna 21 | Student ID : 1741086 22 | Issued Book : ss 23 | Issued date : 30/10/2018 12:35:13 24 | Return date : 30/10/2018 12:35:18 25 | -------------------------------------------------------------------------------- /library_management.java: -------------------------------------------------------------------------------- 1 | import java.util.Date; 2 | import java.io.BufferedReader; 3 | import java.io.BufferedWriter; 4 | import java.io.File; 5 | import java.io.FileReader; 6 | import java.io.FileWriter; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Calendar; 9 | import java.util.HashMap; 10 | import java.util.Map.Entry; 11 | import java.util.Scanner; 12 | import java.util.Set; 13 | 14 | class Student 15 | { 16 | String name; 17 | int id_no; 18 | String Stream; 19 | String book1,book2; 20 | int book_no,issuedbook; 21 | 22 | Student(String name,int id_no,String Stream) 23 | { 24 | this.name=name; 25 | this.id_no=id_no; 26 | this.Stream=Stream; 27 | 28 | } 29 | } 30 | 31 | public class library_management 32 | { 33 | static void Selectionsort( Student arr[]) 34 | { 35 | int n = arr.length; 36 | 37 | for (int i = 0; i < n-1; i++) 38 | { 39 | int min_idx = i; 40 | for (int j = i+1; j < n; j++) 41 | if (arr[j].id_no < arr[min_idx].id_no)//Sort according to ID number of student 42 | min_idx = j; 43 | 44 | String temp1 = arr[min_idx].name; 45 | arr[min_idx].name = arr[i].name; 46 | arr[i].name = temp1; 47 | 48 | String temp2 = arr[min_idx].Stream; 49 | arr[min_idx].Stream = arr[i].Stream; 50 | arr[i].Stream = temp2; 51 | 52 | } 53 | } 54 | 55 | static void display(Student arr[]) 56 | { 57 | for(int i=0;i0) //If book name > root then place it as Right child 102 | root.right = insertRec(root.right, key); 103 | else 104 | System.out.println("error."); 105 | 106 | return root; 107 | } 108 | 109 | void update(String key,String key1) 110 | { 111 | deleteKey(key); 112 | insert(key1); 113 | } 114 | 115 | //Search Book 116 | public boolean containsNode(String value) 117 | { 118 | return containsNodeRecursive(root, value); 119 | } 120 | 121 | private boolean containsNodeRecursive(Node current, String key) 122 | { 123 | if (current == null) 124 | { 125 | return false; 126 | } 127 | //If book name < root then place it as left child 128 | if (key.equalsIgnoreCase(current.key)) 129 | { 130 | return true; 131 | } 132 | 133 | //If book name < root then search at left side of root else right side 134 | return key.compareTo(current.key)<0 135 | ? containsNodeRecursive(current.left, key) 136 | : containsNodeRecursive(current.right, key); 137 | } 138 | 139 | //print tree in 2D 140 | 141 | void printTree() 142 | { 143 | root = printTreeRec(root, 0); 144 | } 145 | 146 | Node printTreeRec(Node t , int space) 147 | { 148 | if(t == null) 149 | return root; 150 | 151 | space += 5; 152 | 153 | printTreeRec(t.right ,space); 154 | 155 | System.out.println(); 156 | 157 | for(int i = 5 ; i < space ; i++) 158 | System.out.print( " "); 159 | System.out.print("[" +t.key+ "]"); 160 | 161 | return printTreeRec(t.left ,space); 162 | } 163 | 164 | 165 | 166 | void deleteKey(String key) 167 | { 168 | root = deleteRec(root, key); 169 | } 170 | 171 | Node deleteRec(Node root, String key) 172 | { 173 | if (root == null) return root; 174 | 175 | //If book name < root then search it at left side and delete 176 | if (key.compareTo(root.key)<0) 177 | root.left = deleteRec(root.left, key); 178 | //If book name > root then search it at right side and delete 179 | else if (key.compareTo(root.key)<0) 180 | root.right = deleteRec(root.right, key); 181 | 182 | else 183 | { 184 | if (root.left == null) 185 | return root.right; 186 | else if (root.right == null) 187 | return root.left; 188 | 189 | root.key = minValue(root.right); 190 | 191 | root.right = deleteRec(root.right, root.key); 192 | } 193 | 194 | return root; 195 | } 196 | 197 | String minValue(Node root) 198 | { 199 | String minv = root.key; 200 | while (root.left != null) 201 | { 202 | minv = root.left.key; 203 | root = root.left; 204 | } 205 | return minv; 206 | } 207 | //Print Books Inorder 208 | void printInorder(Node node) 209 | { 210 | if (node == null) 211 | return; 212 | 213 | printInorder(node.left); 214 | 215 | System.out.print(node.key + " "); 216 | 217 | printInorder(node.right); 218 | } 219 | 220 | void printInorder() 221 | { 222 | printInorder(root); 223 | } 224 | 225 | void inorder() 226 | { 227 | inorderRec(root); 228 | } 229 | 230 | void inorderRec(Node root) 231 | { 232 | if (root != null) 233 | { 234 | inorderRec(root.left); 235 | System.out.println(root.key); 236 | inorderRec(root.right); 237 | } 238 | } 239 | 240 | public static void main(String[] args) throws Exception 241 | { 242 | 243 | input = new Scanner(System.in); 244 | finaldsa tree = new finaldsa(); 245 | HashMap hashmapping = new HashMap<>(); 246 | SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); 247 | Calendar cal = Calendar.getInstance(); 248 | Student[] array =new Student[3]; 249 | //Add student Details 250 | array[0]=new Student("Rajvi",1741078,"B.Tech-ICT"); 251 | array[1]=new Student("Krushna",1741086,"B.Tech-ICT"); 252 | array[2]=new Student("Kalagee",1741052,"B.Tech-ICT"); 253 | int [][] arr=new int[100][2]; 254 | 255 | //Create file to store data of students. 256 | FileWriter fr = new FileWriter("append.txt", true); 257 | BufferedWriter br = new BufferedWriter(fr); 258 | 259 | FileWriter fr1 = new FileWriter("append.txt", true); 260 | BufferedWriter br1 = new BufferedWriter(fr1); 261 | 262 | FileWriter fr2 = new FileWriter("append.txt", true); 263 | BufferedWriter br2 = new BufferedWriter(fr2); 264 | 265 | FileWriter fr3 = new FileWriter("append.txt", true); 266 | BufferedWriter br3 = new BufferedWriter(fr3); 267 | 268 | FileReader file = new FileReader("x.txt"); 269 | BufferedReader reader = new BufferedReader(file); 270 | 271 | FileReader file2= new FileReader("y.txt"); 272 | BufferedReader reader2 = new BufferedReader(file2); 273 | 274 | FileReader file3= new FileReader("z.txt"); 275 | BufferedReader reader3 = new BufferedReader(file3); 276 | 277 | 278 | Date Rday1 = null,Rday2 = null,Cday=null; 279 | boolean e1=false; 280 | 281 | 282 | int i=0; 283 | 284 | while(e1==false) 285 | { 286 | System.out.println("\n....................................." ); 287 | System.out.println("1. Librarian Login. "); 288 | System.out.println("2. User Login. "); 289 | System.out.println("3. Exit. "); 290 | System.out.println("\n....................................." ); 291 | 292 | System.out.println("\nEnter Your choice:"); 293 | int ch1 = input.nextInt(); 294 | 295 | switch(ch1) 296 | { 297 | case 1: //For Librarian login 298 | String pwd1="abc123"; 299 | String id1="dsa@1"; 300 | 301 | System.out.println("\nEnter UserId:" ); 302 | String id2 = input.next(); 303 | 304 | System.out.println("\nEnter Password:" ); 305 | String pwd2=input.next(); 306 | 307 | if(!id1.equals(id2)) 308 | System.out.println("Invalid Userid."); 309 | else if(!pwd1.equals(pwd2)) 310 | System.out.println("Invalid Password."); 311 | else 312 | { 313 | System.out.println("Login succesfully."); 314 | boolean e2=false; 315 | while(e2==false) 316 | { 317 | System.out.println("\n....................................." ); 318 | System.out.println("1. Add book. "); 319 | System.out.println("2. Delete book. "); 320 | System.out.println("3. Update book. "); 321 | System.out.println("4. Print Books Details. "); 322 | System.out.println("5. Print Books in-order. "); 323 | System.out.println("6. Print tree "); 324 | System.out.println("7. Exit"); 325 | 326 | System.out.println("\n....................................." ); 327 | 328 | System.out.println("\nEnter Your choice:"); 329 | int ch2 = input.nextInt(); 330 | 331 | switch(ch2) 332 | { 333 | case 1: //To add a book 334 | 335 | String line; 336 | while((line = reader.readLine()) != null) 337 | { 338 | 339 | tree.insert(line); 340 | hashmapping.put(line, i); 341 | 342 | i++; 343 | } 344 | int j=i; 345 | 346 | int o = 0; 347 | String number; 348 | while((number = reader2.readLine()) != null) 349 | { 350 | int result = Integer.parseInt(number); 351 | if(j!=o) 352 | arr[o][0] = result; 353 | o++; 354 | } 355 | 356 | int pq=0; 357 | String number1; 358 | while((number1 = reader3.readLine()) != null) 359 | { 360 | int result1 = Integer.parseInt(number1); 361 | if(j!=pq) 362 | arr[pq][1] = result1; 363 | pq++; 364 | } 365 | 366 | System.out.println("\nEnter name of book:"); 367 | String name = input.next(); 368 | boolean z1=tree.containsNode(name); 369 | 370 | if(z1==true) 371 | { 372 | System.out.println("\nIt is already exists:"); 373 | } 374 | else 375 | { 376 | System.out.println("\nEnter quantity of book:"); 377 | int quantity = input.nextInt(); 378 | br1.write(name); 379 | br2.write(quantity); 380 | br3.write(quantity); 381 | 382 | tree.insert(name); 383 | hashmapping.put(name, i); 384 | hashmapping.get(name); 385 | arr[i][0]+=quantity;//Total quantity of books 386 | arr[i][1]+=quantity;//Available quantity of books 387 | i++; 388 | } 389 | break; 390 | 391 | case 2: //To delete a book 392 | 393 | System.out.println("\nEnter name of book:"); 394 | String b1 = input.next(); 395 | 396 | boolean x=tree.containsNode(b1); 397 | if(x==true) 398 | { 399 | tree.deleteKey(b1); 400 | hashmapping.remove(b1); 401 | } 402 | 403 | break; 404 | case 3: //To update any book 405 | 406 | System.out.println("\nEnter name of book:"); 407 | String b2 = input.next(); 408 | 409 | boolean z=tree.containsNode(b2); 410 | if(z==true) 411 | { 412 | int a=hashmapping.get(b2); 413 | System.out.println("\nEnter quantity of book to add more:"); 414 | int q = input.nextInt(); 415 | arr[a][0]+=q; 416 | 417 | } 418 | break; 419 | 420 | case 4: //Print Books Details 421 | 422 | Set> setOfEntries = hashmapping.entrySet(); 423 | 424 | for(Entry entry : setOfEntries) 425 | { 426 | int r=entry.getValue(); 427 | System.out.println("Name of book is: " + entry.getKey()); 428 | System.out.println("Total Quantity of book is: " + arr[r][0]); 429 | System.out.println("Available Quantity of book is: " + arr[r][1]); 430 | System.out.println(); 431 | } 432 | 433 | break; 434 | 435 | case 5: //To Print Books in-order 436 | tree.printInorder(); 437 | break; 438 | 439 | case 6://To print binary search tree 440 | tree.printTree(); 441 | break; 442 | 443 | case 7: 444 | e2=true; 445 | break; 446 | 447 | } 448 | } 449 | } 450 | break; 451 | 452 | case 2: //For User Login 453 | 454 | boolean e3=false; 455 | while(e3==false) 456 | { 457 | System.out.println("\n....................................." ); 458 | System.out.println("1. Issue book. "); 459 | System.out.println("2. Return book. "); 460 | System.out.println("3. Exit"); 461 | System.out.println("\n....................................." ); 462 | 463 | System.out.println("\nEnter Your choice:"); 464 | int ch3 = input.nextInt(); 465 | 466 | switch(ch3) 467 | { 468 | case 1://To issue a book 469 | int index = -1; 470 | System.out.println("\nEnter your id:"); 471 | int id = input.nextInt(); 472 | 473 | //display(array); 474 | for(int k=0;k<3;k++) 475 | { 476 | if(array[k].id_no==id) 477 | index=k; 478 | 479 | } 480 | if(index!=-1) 481 | { 482 | if(array[index].book_no==2) 483 | { 484 | System.out.println("\nYou can't issue more than two books."); 485 | } 486 | else 487 | { 488 | System.out.println("\nEnter name of book:"); 489 | String book = input.next(); 490 | boolean x=tree.containsNode(book); 491 | if(x==true) 492 | { 493 | int a=hashmapping.get(book); 494 | if(arr[a][1]>0) 495 | { 496 | if(array[index].book1==null) 497 | array[index].book1=book; 498 | else 499 | array[index].book2=book; 500 | System.out.println("Book issued successfully."); 501 | arr[a][1]--; 502 | Cday=cal.getTime(); 503 | System.out.println("Currunt Date Time : " + formatter.format(cal.getTime())); 504 | cal.add(Calendar.SECOND, 5); 505 | Rday1 = cal.getTime(); 506 | System.out.println("Due Date Time: " + formatter.format(Rday1)); 507 | array[index].book_no++; 508 | 509 | br.write("\nStudent name: " + array[index].name); 510 | br.write("\nStudent ID : " + array[index].id_no); 511 | br.write("\nIssued Book : " + book); 512 | br.write("\nIssued date : " + formatter.format(Cday)); 513 | br.write("\nReturn date : " + formatter.format(Rday1)); 514 | 515 | } 516 | else 517 | System.out.println("You can not issue book now.\nTry again after some days"); 518 | } 519 | else 520 | System.out.println("Book is not available."); 521 | } 522 | 523 | } 524 | else 525 | System.out.println("Invalid ID"); 526 | break; 527 | 528 | case 2://to return a book 529 | 530 | try 531 | { 532 | int ind = -1; 533 | System.out.println("\nEnter your id:"); 534 | int s_id = input.nextInt(); 535 | System.out.println("\nEnter name of book:"); 536 | String Rbook = input.next(); 537 | for(int k=0;k<3;k++) 538 | { 539 | if(array[k].id_no==s_id && (array[k].book1.equalsIgnoreCase(Rbook)==true || array[k].book2.equalsIgnoreCase(Rbook)==true)) 540 | ind=k; 541 | 542 | } 543 | 544 | if(ind!=-1) 545 | { 546 | 547 | boolean y=tree.containsNode(Rbook); 548 | 549 | if(y==true) 550 | { 551 | 552 | if(array[ind].book1.equalsIgnoreCase(Rbook)==true) 553 | array[ind].book1=null; 554 | else 555 | array[ind].book2=null; 556 | 557 | cal = Calendar.getInstance(); 558 | Rday2=cal.getTime(); 559 | //System.out.println(Rday2 + "&"+ Rday1); 560 | 561 | if(Rday2.after(Rday1)) 562 | { 563 | System.out.println("Book is overdue."); 564 | long diff=Rday2.getTime()-Rday1.getTime(); 565 | int noofdays=(int)(diff/(2000/**24*60*60*/)); 566 | System.out.println("Due Date Time: " + formatter.format(Rday2)); 567 | System.out.println("book is delayed by " + noofdays + "seconds." + diff); 568 | double charge =noofdays*5; 569 | System.out.println("Your charge is: " + charge + "Rs." ); 570 | } 571 | else 572 | { 573 | System.out.println("Book is returned successfully."); 574 | } 575 | 576 | 577 | int a=hashmapping.get(Rbook); 578 | arr[a][1]++; 579 | array[ind].book_no--; 580 | } 581 | } 582 | 583 | else 584 | System.out.println("Invalid ID"); 585 | } 586 | catch(Exception e) 587 | { 588 | System.out.println("Something is going to be wrong."); 589 | } 590 | break; 591 | 592 | case 3: 593 | e3=true; 594 | 595 | break; 596 | } 597 | } 598 | break; 599 | 600 | case 3: 601 | e1=true; 602 | 603 | break; 604 | } 605 | 606 | } 607 | br.close(); 608 | fr.close(); 609 | br1.close(); 610 | fr1.close(); 611 | br2.close(); 612 | fr2.close(); 613 | br3.close(); 614 | fr3.close(); 615 | reader.close(); 616 | reader2.close(); 617 | reader3.close(); 618 | 619 | } 620 | } -------------------------------------------------------------------------------- /x.txt: -------------------------------------------------------------------------------- 1 | dsa 2 | abc 3 | la 4 | co 5 | -------------------------------------------------------------------------------- /y.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | -------------------------------------------------------------------------------- /z.txt: -------------------------------------------------------------------------------- 1 | 1 2 | 2 3 | 3 4 | 4 5 | --------------------------------------------------------------------------------