Question

In Python !!!

In this exercise you will continue to work with Classes and will build on the Book class in Lab 13.10; you should copy the code you created there as you will need to extend it in this exercise. You will extend the Book class to accommodate the case where there may be multiple authors for a book. The attribute author should become a list. The constructor will still take a parameter that is a string for author, as before, but the constructor will now create a list. If there is a single author, then then it will be a list of one. You will also add a new method, addAuthor which has parameters self and a string which is another author. The method will then append this new author to the list of authors for the attribute *author Finally, you will need to extend the repr method to print a book with multiple authors. The main program, given, reads a file and uses your extended class Book to build a list of books and print it out The first part of the output should look like: Book A Brief History of Time, written by Stephen Hawking, was published in 1990 Book The Hitchhikers Guide to the Galaxy, written by Douglas Adams, was published in 1979 Book The God Delusion, written by Richard Dawkins, was published in 2006 Book The Da Vinci Code, written by Dan Brown, was published in 2003 Book Good Omens, written by Neil Gaiman and Terry Pratchett, was published in 1990

Current file: main.py 1# 2 # main program for simple use of book class 3# 5 from multiple_authors import * 7 if-name--== --main--: 9 # Complete main section of code 10 11 COMMA = 12 DIVIDER - 13 14 # prompt user for file name holdng list of books and authors 15 il_nameinput(Enter fil with books: ) 1 niopeniler 17 .

18 mybooks = for line in inf: 19 21 23 25 27 line line.stripO values-line.split(DIVIDER) title - values [0] auths values [1] year = values[2] if COMMA in auths: authlist-auths.split(COMMA) abook Book(title,authlist[Ø],year) for i in range(1,lenCauthlist)): 28 abook.addAuthor(authlist[i]) else: 31 32 abook Book(title,auths,year) mybooks.appendCabook)

34 # now, print list of books using method in Book class 35 print(List of books is: 36 or b in mybooks: 37 38 print(b)

Current file: multiple_authors.py 1# 2 # class book 3# 4 5 class Book def -init--(self, # complete the definition of the constructor 7 title- , author- .year=) : 10 def getTitle(self): return self.title 12 13 14 15 def getAuthor(self): return self.author def getYear(self) return self.year 17 18

Current file: multiple..authors.py ▼ 12 13 def getAuthor(self): return self.author 15 16 17 18 def getYear(self): return self.year def setTitle(self,atitle): self.title atitle 20 21 22 def setYear (self,yr): 23 24 25 def addAuthor(self,auth): 26 27 28 def__repr.(self) 29 self.year- yr # complete the definition of addAuthor # complete the definition of repr

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
In Python !!! In this exercise you will continue to work with Classes and will build...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • You need to program a simple book library system. There are three java classes Book.java   //...

    You need to program a simple book library system. There are three java classes Book.java   // book object class Library.java   //library class A2.java //for testing The Book.java class represents book objects which contain the following fields title: a string which represents the book title. author: a string to hold the book author name year: book publication year isbn: a string of 10 numeric numbers. The book class will have also 3 constructors. -The default no argument constructor - A constructor...

  • MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access...

    MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...

  • MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access...

    MUST BE WRITTEN IN C++ Objective: Learn how to define structures and classes, create and access a vector of structures, use sort with different compare functions. Assignment: Your program will use the same input file, but you will print the whole book information, not just the title. And, most importantly, this time you will take an object oriented approach to this problem. Detailed specifications: Define a class named Collection, in which you will define a structure that can hold book...

  • C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Ever...

    C++ In this homework, you will implement a single linked list to store a list of computer science textbooks. Every book has a title, author, and an ISBN number. You will create 2 classes: Textbook and Library. Textbook class should have all above attributes and also a "next" pointer. Textbook Туре String String String Attribute title author ISBN Textbook* next Library class should have a head node as an attribute to keep the list of the books. Also, following member...

  • Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors....

    Using C++ Skills Required Create and use classes Exception Handling, Read and write files, work vectors. Create Functions, include headers and other files, Loops(while, for), conditional(if, switch), datatypes,  etc. Assignment You work at the computer science library, and your boss just bought a bunch of new books for the library! All of the new books need to be cataloged and sorted back on the shelf. You don’t need to keep track of which customer has the book or not, just whether...

  • Each question needs a screenshot of the result and the code. insert appropriate amount of comments...

    Each question needs a screenshot of the result and the code. insert appropriate amount of comments in the code. Exercise-1: Plant class. Define a class Plant that satisfies the spec below. Hints A. For this problem, provide an implementation for the Plant spec below, and test it using the example calls provided B. Although the constructor is described in the spec (and called) using the name Plant), the internal name for a class's constructor is_init__(). (There are two underscores before...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes,...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Create a Python file (book.py) that has a class named Book. Book class has four attributes, title...

    Create a Python file (book.py) that has a class named Book. Book class has four attributes, title (string), author(string), isbn(string), and year(int). Title - the name of the book. Author - the name of the persons who wrote the book. ISBN - is a unique 13 digit commercial book identifier. Year - the year the title was printed. Your class should have the following methods: (1) __init__(self, title, author, isbn, year): This method called when an object (book) is created...

  • Complete the function load_trees_from_file() specified in A1.py It should take as a parameter the name of...

    Complete the function load_trees_from_file() specified in A1.py It should take as a parameter the name of a file containing a set of trees and return a list containing instances of the Tree class representing all of the trees listed in the file. If the file does not exist, it should print that the file is not found and return None. You will need to include your Tree class definition from Question 1 in your answer. Consider the following code fragment:...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT