Page 1 of 1

Instructions You will need to create four files: Book.py - file containing a class definition for a Book object . BookCo

Posted: Sat May 14, 2022 7:53 pm
by answerhappygod
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 1
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 1 (58.56 KiB) Viewed 37 times
removeAuthor(self, author)
recursiveSearchTitle(self, title, bookNode)
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 2
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 2 (58.56 KiB) Viewed 37 times
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 3
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 3 (68.1 KiB) Viewed 37 times
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 4
Instructions You Will Need To Create Four Files Book Py File Containing A Class Definition For A Book Object Bookco 4 (71.69 KiB) Viewed 37 times
Instructions You will need to create four files: Book.py - file containing a class definition for a Book object . BookCollection.py - file containing a class definition for a collection of Books that will be implemented as an Ordered Linked List • BookcollectionMode - file containing a class definition for a Node in the Book Collection • testFile.py - file containing pytest functions testing the overall correctness of your class definitions There will be no starter code for this assignment, but rather the class descriptions and required methods are defined in the specification below. You should organize your lab work in its own directory. This way all files for a lab are located in a single folder. Also, this will be easy to import various files into your code using the import / from technique shown in lecture. Book.py class The Book.py file will contain the definition of a Book. We will define the Book attributes as follows: . title - str that represents the title of the Book author - str that represents the author of the Book. This will be in a LastName, FirstName format. You may assume this will always be the case year - int that represents the year the Book was published You should write a constructor that allows the user to construct a book object by passing in valuies for all of the fields. Your constructor should set the title and author attribues to empty strings ("), and the year attribute to None by default. _init_(self, title, author, year) In addition to your constructor, your class definition should also support "getter" methods that can receive the state of the Book object: getTitlelser getAuthorsen .getYear(self) You will implement the method .getBook Details self that returns a str with all of the Book attributes. The string should contain all attributes in the following EXACT format (Note: There is no n character at the end of this string): b - Book("Ready Player One","cline, E Ernest", 2011) print(b.getBookDetails) Output Title: Ready Player One, Author: Cline, Ernest, Year: 2011 . Lastly, your Book class should overload the operator 9). This will be used when finding the proper position of a Book in the Ordered Linked List using the specification above. We can compare books using the operator while walking down the list and checking if the inserted book is > than a specific Book in the Ordered Linked List

Book Collection.py and Book CollectionNode.py The Book CollectionMode, py file will define the Book Collector de class. This will be similar to the linked List Node implementation done in lecture. You will need to write the following methods: _init__(self, tata) - constructor that will assign the parameter data (a Book object) as part of this node. Each node will also have a next reference associated with it. When constructing a Book alleetanlode, the next reference should be None by default .getDataselt) -getter method that returns the data (Book object) • getNext (self) - getter method that returns the next Bookceletbetode in the Linked List structure .setDataselt, newtata) - updates the Node's data with the parameter newData . sethuext(self, neutekt) - updates the Node's next reference with the newest parameter (another nokCollectiontode) The Bookcollection.py file will contain the definition of a collection of Book objects stored in an Ordered Linked List. The Book Collection will manage an Ordered Linked List containing Bookcollections. The Book Collectton class will be responsible for maintaining the overall structure of the Ordered Linked List. Your Book Collection class will need to support the following methods: . _init_Iself) - constructor that will have a head reference that references the first node in the Ordered Linked List. This should be set to None by default. • isemptyiselt) - method that returns True (boolean) if the Book Collection is empty, and returns False otherwise • pethunbero Books self-method that returns the total number of Books (int) in the Book Collection .inserthookself, tookl - method that inserts a Book in the appropriate place. As mentioned before, all Books in the Book Collection are ordered based on 1) the Book's author (alphabetical Sexicographical order), then 2) the Book's year of publication, and then 3) the Book's title (alphabetical/lexicographical order). Here is where we can utilize the Book's operator. You'll need to do some logic to replace the references for the Book Collection Nodes when inserting the Book in the appropriate place. • getook sayAuthoriself, author) - method that returns a str containing all of the Book details by a specified author. Note that each book will be in its own line (each line ending with a character). Also note that the input parameter (author) may be in a different case than the case of the author that the book was constructed with - in this situation, the comparison of the authors' names should be case insensitive ('=). An example (with correct order) is shown below: be - Book("Cujo", "King, Stephen", 1981) bi - Book "The Shining", "King, Stephen, 1977) b2 = Book"Ready Player One", "Cine, Ernest", 2011) b3 - Book"Rage", "King, Stephen", 1977) bc = BookCollection() bc.insertBook(be) bc.insertBook(bi) bc.insertBook (2) bc.insertBook (3) print(bc.getBooksüyAuthor("KING, Stephen“); Output: Title: Rage, Author: King, Stephen, Year: 1977 Title: The Shining, Author: King, Stephen, Year: 1977 Title: Cujo, Author: King, Stephen, Year: 1981 . petal tlooksInCollection(self) - method that returns a str containing the details of all Books in the Book Collection Note that each book will be in its own line (each line ending with a character). An example (with correct order) is shown below: be - Book("Cujo", "King, Stephen", 1981) bi = Book("The Shining", "King. Stephen", 1977) b2 = Book Ready Player One", "Cline, Ernest", 2011) b3 = Book("Rage", "King, Stephen", 1977)

bc = BookCollection() bc.insertBook(be) bc.insertBook(b1) bc.insertBook(b2) bc.insertBook(b3) print(bc.getAllBooksInCollection()) Output: Title: Ready Player One, Author: Cline, Ernest, Year: 2011 Title: Rage, Author: King, Stephen, Year: 1977 Title: The Shining, Author: King, Stephen, Year: 1977 Title: Cujo, Author: King, Stephen, Year: 1981 removeAuthoriselt, author) - method that removes all Books written by a specified author. Since this is an Ordered Linked List, all Books written by a specific author should be located right next to each other in the Book Collection assuming your insertBook method has been implemented correctly. Note: the input parameter (author) may be in a different case than the case of the author that the book was constructed with - your solution must account for these situations. recursiveSearchTitletself, title, bookNode) - method that searches the Bookcollection for a specific Book title passed in the method. Note: this method must be done recursively. This method will return True if a Book in the Book Collection has the same title as the parameter title (str), and return false otherwise. Since this solution is recursive, this method will take in a reference to a BookCollectionMode object (bookliede) in the Bookcollection that needs to be searched. The initial call to recursiveSearchTitle would pass in the head of the Bookcollection since that's the starting point to search through the entire Bookcollection. For example: b = Book("Cujo", "King, Stephen", 1981) bi = Book("The Shining", "King, Stephen", 1977) bc = Bookcollection() bc.insertBook(be) bc.insertBook(51) assert bc.recursiveSearchTitle("CUJO", bc.head) == True assert bc.recursiveSearchTitle("Twilight", bc.head) == False . You can then recursively search through the Bookcollection sub parts by recursively referring to the next BookcollectionNode in Bookcollection that needs to be searched if the Book in bookNode does not have the title we're looking for. Note: the input parameter title may be in a different case than the case of the title that the Book was constructed with your solution must account for these situations (see assert statement above). testFile.py pytest This file should import your Book, Bookcollection, and Bookcollection Node classes so you can write unit tests using pytest to test your functionality is correct. Think of various scenarios and edge cases when testing your code. Write your tests first in order to check the correctness of the Book, Bookcollection and BookCollection Node methods. Gradescope requires testfile.py to be submitted before running any autograded tests. You should write at least one test for each method in each of these classes (but more tests can help you debug various cases!). m