Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.43 KB | None | 0 0
  1. class client:
  2.     def __init__(self, name, surname):
  3.         self.name = name
  4.         self.surname = surname
  5.         self.borrowedBooks = []
  6.  
  7. class library:
  8.     def __init__(self):
  9.         self.__clients = []
  10.         self.__books = []
  11.  
  12.     def addClient(self, client):
  13.         self.__clients.append(client)
  14.  
  15.     def printClients(self):
  16.         for client in self.__clients:
  17.             print(client.name + ' ' + client.surname)
  18.  
  19.     def addBook(self, book):
  20.         self.__books.append(book)
  21.  
  22.     def printBooks(self):
  23.         for book in self.__books:
  24.             print(book.title + ' ' + str(book.code))
  25.    
  26.     def lend(self, code, client):
  27.         bookToBorrow = self.findBook(code)
  28.         client.borrowedBooks.append(bookToBorrow)
  29.    
  30.     def findBook(self, code):
  31.         for book in self.__books:
  32.             if code == book.code:
  33.                 return book
  34.        
  35.  
  36. class book:
  37.     def __init__(self, code, title, authors):
  38.         self.authors = authors
  39.         self.code = code
  40.         self.title = title
  41.  
  42.  
  43. class author:
  44.     def __init__(self, name, surname):
  45.         self.name = name
  46.         self.surname = surname
  47.  
  48.  
  49. mainLib = library()
  50. client1 = client("Jan", "Kowalski")
  51. mainLib.addClient(client1)
  52. mainLib.printClients()
  53.  
  54. book1 = book(123, 'Robin Hood', 'Sara B.')
  55. mainLib.addBook(book1)
  56. mainLib.printBooks()
  57. mainLib.lend(123,client1)
  58.  
  59. print(client1.borrowedBooks[0].title + " is borrowed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement