Question: You are to create an application that will read data from a file and store it in a collection of objects. You will create

You are to create an application that will read data from a

file and store it in a collection of objects. You will create 

 

You are to create an application that will read data from a file and store it in a collection of objects. You will create a class called Bookstore which will maintain a list of Book objects (the second class you will create). Methods of Bookstore: load - takes a string representing a filename, opens the file, reads the data, splits it into components, trims any extra whitespace and converts the data where necessary, and adds Book objects to the list accordingly. Don't forget to close the file when done. add - takes the following parameters: title, subtitle, edition, authors (edition is always an integer, everything else is a string), creates a Book from it, and then adds that book to the list. remove - takes a title and edition, finds the first book in the list that matches the criteria, and removes it from the list, returning True. If it cannot find the book, it returns False (Hint: you can assume that you won't find the item that is, set a local variable to False - then, if you find it, set that same variable to True. Regardless, at the end of the problem, you return the status, which will be False unless you found a match.) _str_- returns a string which is a formatted list of books, looking like the following: Big Java Late Objects 2 Cay Horstmann Digital Design 6 Mano & Ciletti Cloud Commuting Of course, it's obvious there are more than two books. Note that if the subtitle is blank, it is NOT printed. You ask a Bookstore to stringify itself with the str function, which you have used on things like integers when printing. This method works by asking each Book object to stringify itself (using the str function). After each book, a newline is printed (to separate the books). . The constructor of Bookstore sets up the empty list as an instance variable and calls the load method on a supplied filename. Methods of Book: Book requires: its constructor, which takes the title, subtitle, edition, and author (remember, the edition is an integer), and stores them in instance variables. its_str_ method, which returns the Book in string form accessors (getters) for each of the instance variables (for example, get_title would get the title)

Step by Step Solution

3.49 Rating (146 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

ANSWER Below is the Python code that implements the Book and Bookstore classes according to your req... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!