The first part is “addBook method” the Second part is “checkOut method” the third part is “isAvailable method” and the fourth is “__str__ method”. What you have to do is complete the sample code provided below. do not change the sample code and print result. The program's goal is to keep track of books in a library. Books are stored in dictionaries, with the book title as the key.
Source Code is:
class Library:
bookCount = 0
def __init__(self):
self.cardCatalog = dict()
self.checkedOut = dict()
# PART 1
# Add the book to cardCatalog. title is the key, author is the
value
# Add the book to checkedOut. title is the key, False is the
value
def addBook(self, author, title):
pass
# PART 2
#
# Check to see if the title is in checkedOut dictionary.
# If so, set the value to True
def checkOut(self, author, title):
pass
# PART 3
#
# Check to see if the title is in checkedOut.
# If it isn't return False
# If it is, and the value is True, return False
# If the value is False, return True
# (Note that it appears reversed. Being checked out means it's not
available
def isAvailable(self, author, title):
pass
# PART 4
#
# Return a string that contains multiple lines.
# Each line is a title followed by the author name.
# Hint: Create a string and append title, name, and a newline
"\n"
# then return the string
def __str__(self):
pass
#
# Code to test the program
#
# DO NOT CHANGE THE CODE BELOW.
#
# Your output should be:
# False
# A Fall of Moondust Arthur C. Clarke
# Pandora's Star Peter F. Hamilton
# Ringworld Larry Niven
# <blank line> <= No brackets, just one blank line, makes
__str__ easier
#
lib = Library()
lib.addBook("Peter F. Hamilton", "Pandora's Star")
lib.addBook("Arthur C. Clarke", "A Fall of Moondust")
lib.addBook("Larry Niven", "Ringworld")
lib.checkOut("Peter F. Hamilton", "Pandora's Star")
print(lib.isAvailable("Hamilton", "Pandora's Star"))
print(lib)
PYTHON CODE:
class Library:
bookCount = 0
def __init__(self):
self.cardCatalog =
dict()
self.checkedOut =
dict()
# PART 1
# Add the book to cardCatalog. title is the key,
author is the value
# Add the book to checkedOut. title is the key,
False is the value
def addBook(self, author, title):
self.cardCatalog[title]=author
self.checkedOut[title]=False
# PART 2
#
# Check to see if the title is in checkedOut
dictionary.
# If so, set the value to True
def checkOut(self, author, title):
for key in self.checkedOut.keys():
if key == title:
self.checkedOut[title]=True
break
# PART 3
#
# Check to see if the title is in
checkedOut.
# If it isn't return False
# If it is, and the value is True, return
False
# If the value is False, return True
# (Note that it appears reversed. Being checked
out means it's not available
def isAvailable(self, author, title):
for key,value in
self.checkedOut.items():
if key == title and value == True:
return False
if key == title and value == False:
return True
# PART 4
#
# Return a string that contains multiple
lines.
# Each line is a title followed by the author
name.
# Hint: Create a string and append title, name,
and a newline "\n"
# then return the string
def __str__(self):
s = ''
titles = sorted(self.cardCatalog.keys())
for title in titles:
for key,value in self.cardCatalog.items():
if title == key:
s += key +' '+ value+'\n'
break
return s
#
# Code to test the program
#
# DO NOT CHANGE THE CODE BELOW.
#
# Your output should be:
# False
# A Fall of Moondust Arthur C. Clarke
# Pandora's Star Peter F. Hamilton
# Ringworld Larry Niven
# <blank line> <= No brackets, just one blank line, makes
__str__ easier
#
lib = Library()
lib.addBook("Peter F. Hamilton", "Pandora's Star")
lib.addBook("Arthur C. Clarke", "A Fall of Moondust")
lib.addBook("Larry Niven", "Ringworld")
lib.checkOut("Peter F. Hamilton", "Pandora's Star")
print(lib.isAvailable("Hamilton", "Pandora's Star"))
print(lib)
SCREENSHOT FOR CODING:

SCREENSHOT FOR OUTPUT:

The first part is “addBook method” the Second part is “checkOut method” the third part is...
A library maintains a collection of books. Books can be added to
and deleted from and checked out and checked in to this
collection.
Title and author name identify a book. Each book object
maintains a count of the number of copies available and the number
of copies checked out. The number of copies must always be greater
than or equal to zero. If the number of copies for a book goes to
zero, it must be deleted from the...
please Code in c++ Create a new Library class. You will need both a header file and a source file for this class. The class will contain two data members: an array of Book objects the current number of books in the array Since the book array is moving from the main.cc file, you will also move the constant array size definition (MAX_ARR_SIZE) into the Library header file. Write the following functions for the Library class: a constructor that initializes...
Hey I have a task which consists of two part. Part A asks for
writing a program of WORD & LINE CONCORDANCE
APPLICATION in python which I have completed it.
Now the second part has given 5 dictionary implementation codes
namely as: (ChainingDict, OpenAddrHashDict with linear probing,
OpenAddrHashDict with quadratic probing, and 2 tree-based
dictionaries from lab 12 (BST-based dictionary implementation) and
asks for my above program WORD & LINE CONCORDANCE
APPLICATION to use these implemented code and
show the time...