Multimedia Library (OOP Concepts)
Edit in new window
bubble
play_circle
Run
stop_circle
Stop
cancel
Clear
text_increase
text_decrease
light_mode
routine
dark_mode
restart_alt
Reset
download_for_offline
Download
help
Help
main.py
items.py
⨯
library.py
⨯
+
#Multimedia Library - www.101computing.net/multimedia-libary-oop-concepts/ from items import CD, DVD, Book from library import Library myLibrary = Library() book1 = Book("Enigma","A fiction book taking place at Bletchley Park in 1943.","Robert Harris","978-0099527923") book2 = Book("Life 3.0","Being Human in the Age of Artificial Intelligence.","Max Tegmark","978-0141981802") book3 = Book("The Code Book","The Science of Secrecy from Ancient Egypt to Quantum Cryptography.","Simon Singh","978-1857028898") dvd1 = DVD("The Imitation Game","A historical drama film, based on the 1983 biography Alan Turing: The Enigma by Andrew Hodges.","Morten Tyldum","12") cd1 = CD("Divide","Released in March 2017.","Ed Sheeran","Pop/Rock",12) myLibrary.addItem(book1) myLibrary.addItem(book2) myLibrary.addItem(book3) myLibrary.addItem(dvd1) myLibrary.addItem(cd1) myLibrary.listItems()
class Item: # Constructor def __init__(self,title,description): self.title = title self.description = description #Abstract Method to be immplemented in child classes (over-riding polymorphism) def viewDescription(self): return class DVD(Item): def __init__(self,title,description,director,certificate): super().__init__(title,description) self.director = director self.certificate = certificate def viewDescription(self): print("DVD Title: " + self.title) print("Description: " + self.description) print("Director: " + self.director) print("Certificate: " + self.certificate) class CD(Item): def __init__(self,title,description,artist,genre,numberOfTracks): super().__init__(title,description) self.artist = artist self.genre = genre self.numberOfTracks = numberOfTracks def viewDescription(self): print("CD Title: " + self.title) print("Description: " + self.description) print("Artist: " + self.artist) print("Genre: " + self.genre) print("Number of Tracks: " + str(self.numberOfTracks)) class Book(Item): def __init__(self,title,description,author,isbn): super().__init__(title,description) self.author = author self.isbn = isbn def viewDescription(self): print("Book Title: " + self.title) print("Description: " + self.description) print("Author: " + self.author) print("ISBN: " + self.isbn)
from items import CD, DVD, Book class Library: # Constructor def __init__(self): self.items = [] #A list of all the items in the library # A method to add an item to the library def addItem(self,item): self.items.append(item) # A method to remove an item from the library def removeItem(self,item): self.items.remove(item) # A method to view all items. def listItems(self,fullDescription = True): if fullDescription: print("---------------------") for item in self.items: item.viewDescription() print("---------------------") else: print("---------------------") for item in self.items: item.name print("---------------------") # A method to return the number of items in the library def numberOfItems(self): return len(self.items) # A method to empty the content of the library def reset(self): self.items = [] # A method to return whether the library is empty or not: def isEmpty(self): return len(self.items)==0
task_alt