Shahd_Elmeniawy

Library Management System

Jan 30th, 2025 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. class Book:
  2.     def __init__(self, title, author, ISBN, status):
  3.         self.title = title
  4.         self.author = author
  5.         self.ISBN = ISBN
  6.         self._status = status
  7.  
  8.     def __repr__(self):
  9.         print(self.title)
  10.         print(self.author)
  11.         print(self.ISBN)
  12.         print(self._status)
  13.  
  14.     def getTitle(self):
  15.         return self.title
  16.    
  17.     def getStatus(self):
  18.         return self._status
  19.    
  20.     def setStatus(self, check):
  21.         self._status = check
  22.  
  23. ################################################################
  24.  
  25. class User:
  26.     def __init__(self, name, ID, borList):
  27.         self.name = name
  28.         self.ID = ID
  29.         self.borlist = borList
  30.  
  31.     def __repr__(self):
  32.         print(self.name)
  33.         print(self.ID)
  34.         print(self.borlist)
  35.    
  36.     def borrowBookByTitle (self, libaryObj, bookTitle):
  37.         booktoborrow = libaryObj.SearchBook(bookTitle)
  38.         if booktoborrow.getStatus() == True:
  39.             self.borlist.append(booktoborrow)
  40.             booktoborrow.setStatus(False)
  41.         else:
  42.             print("This Book is unvaliable")
  43.  
  44.        
  45. ############################################################
  46.        
  47. class Library:
  48.     def __init__(self):
  49.         self.users = []
  50.         self.books = []
  51.    
  52.     def AddUser(self, obj1):
  53.         self.users.append(obj1)
  54.  
  55.     def AddBook(self, obj1):
  56.         self.books.append(obj1)
  57.    
  58.  
  59.     def SearchBook (self, BookName):
  60.         for bookobj in self.books:
  61.             if bookobj.getTitle() == BookName:
  62.                 return bookobj
  63.         return Book("", "", "", False)
  64.  
  65. ################################################################################33
  66.  
  67. MyLibrary = Library()
  68. MyLibrary.AddUser(User("Ahmed", "123", []))
  69. MyLibrary.AddUser(User("Mohamed", "1230", []))
  70. MyLibrary.AddBook(Book("C++", "abc", "123451", True))
  71.  
  72. MyLibrary.users[0].borrowBookByTitle(MyLibrary, "Python")
  73.  
  74.  
Add Comment
Please, Sign In to add comment