Question

In: Computer Science

Language: Python Implement the Book class as demonstrated below. You should not change the Book methods...

Language: Python

Implement the Book class as demonstrated below. You should not change the Book methods and implementation as provided. The docstrings in the template contain descriptions of each method.

>>> b=Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001)

>>> b

Book ( ' Code' , 'Charles Ptzold' 'Computing' , 2001)

>>> str (b)

' Code : Charles Ptzold: Computing: 2001 '

>>> b. getTitle ( )

' Code '

>>> b. getAuthor()

' Charles Ptzold'

>>> b. getPublicationYear( )

2001

>>> b*10

[Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) , Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001) ,Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001)]

>>> b2=Book( ' Code' , 'Charles Ptzold' 'Computing' , 2001)

True

>>> b3=Book( ' Code' , 'Charles Ptzold' 'Computing' , 2003)

False

__________________________________________________________________________

import random

class Book(object):

    def __init__(self,title='',author='', genre='', yearOfPublication=0):

        'constructor.'

        pass

    def getTitle(self):

        'get book title'

        pass

    def getAuthor(self):

        'get book author'

        pass

    def getGenre(self):

        'get book genre'

        pass

    def getPublicationYear(self):

        'get publication year'

        pass

    def __mul__(self,count):

        'makes copies of the book and returns a list of all the copies'

        pass

   

    def __eq__(self,other):

        'Compares two books. returns True if all properites of a book are the same, False otherwise'

        pass

   

    def __str__(self):

        'string representation of Book'

        pass

   

    def __repr__(self):

        'python representation of Book'

        pass

Solutions

Expert Solution

import random

class Book(object):
def __init__(self,title='',author='', genre='', yearOfPublication=0):
'constructor.'
self.title=title
self.author=author
self.genre=genre
self.yearOfPublication=yearOfPublication
  
def getTitle(self):
'get book title'
return self.title

def getAuthor(self):
'get book author'
return self.author

def getGenre(self):
'get book genre'
return self.genre

def getPublicationYear(self):
'get publication year'
return self.yearOfPublication
  
def __mul__(self,count):
'makes copies of the book and returns a list of all the copies'
l=[]
for i in range(count):
l.append(Book(self.title,self.author,self.genre,self.yearOfPublication))
return l
  
def __eq__(self,other):
'Compares two books. returns True if all properites of a book are the same, False otherwise'
if(self.title==other.getTitle()):
if(self.author==other.getAuthor()):
if(self.genre==other.getGenre()):
if(self.yearOfPublication==other.getPublicationYear()):
return True
return False

def __str__(self):
'string representation of Book'
return self.title+" : "+self.author+": "+self.genre+": "+str(self.yearOfPublication)

def __repr__(self):
'python representation of Book'
return "Book ( '" +self.title+"' , '"+self.author+"' '"+self.genre+"' , "+str(self.yearOfPublication)+")"

Screenshots:

The screenshots are attached below for reference.

Please follow them for output and proper indentation.

Please upvote my answer. Thank you.


Related Solutions

By using Python: a. Make a class called Book. The __init__() method for Book should store...
By using Python: a. Make a class called Book. The __init__() method for Book should store two attributes: a title and an author. Make a method called book_info() that prints these two pieces of information, and a method called book_available() that prints a message indicating that the book is available in the library. b. Create an instance called book1 from your class. Print the two attributes individually, and then call both methods. c. Create three different instances from the class,...
Implement the following methods. Assume that these will be methods within your myArray class. operator[] Should...
Implement the following methods. Assume that these will be methods within your myArray class. operator[] Should take in an int and return arr at that index if it is a valid index notEqual The notEqual should take in another myArray object and return true if the objects are not equal to one another and false if they are equal. operator-(float) Will subtract the float value that is passed in from each of the values in arr Copy constructor Will take...
Java programming language should be used Implement a class called Voter. This class includes the following:...
Java programming language should be used Implement a class called Voter. This class includes the following: a name field, of type String. An id field, of type integer. A method String setName(String) that stores its input into the name attribute, and returns the name that was just assigned. A method int setID(int) that stores its input into the id attribute, and returns the id number that was just assigned. A method String getName() that return the name attribute. A method...
In simple Java language algorithm: Implement a static stack class of char. Your class should include...
In simple Java language algorithm: Implement a static stack class of char. Your class should include two constructors. One (no parameters) sets the size of the stack to 10. The other constructor accepts a single parameter specifying the desired size of the stack a push and pop operator an isEmpty and isFull method . Both return Booleans indicating the status of the stack Using the stack class you created in problem 1), write a static method called parse that parses...
In this homework you will implement a Library class that uses your Book and Person class...
In this homework you will implement a Library class that uses your Book and Person class from homework 2, with slight modifications. The Library class will keep track of people with membership and the books that they have checked out. Book.java You will need to modify your Book.java from homework 2 in the following ways: field: dueDate (private)             A String containing the date book is due.  Dates are given in the format "DD MM YYYY", such as "01 02 2017"...
Please create a python module named homework.py and implement the classes and methods outlined below. Below...
Please create a python module named homework.py and implement the classes and methods outlined below. Below you will find an explanation for each class and method you need to implement. When you are done please upload the file homework.py to Grader Than. Please get started as soon as possible on this assignment. This assignment has many problems, it may take you longer than normal to complete this assignment. This assignment is supposed to represent a group of students in a...
PYTHON - please finish the methods below that are apart of a linkedlist class #return the...
PYTHON - please finish the methods below that are apart of a linkedlist class #return the data value at index(position) in the list. values remain unchanged def __getpos__(self, position): #do not change, checks for valid index if self.size == 0: raise IndexError elif position is None: return self.pop(self.size - 1) elif type(position) != int: raise TypeError elif position < 0 or position >= self.size: raise IndexError #replace the data value at requested position(index). return nothing def __setpos__(self,position,value): #do not change,...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is...
Programming Language: C# CheckingAccount class You will implement the CheckingAccount Class in Visual Studio. This is a sub class is derived from the Account class and implements the ITransaction interface. There are two class variables i.e. variables that are shared but all the objects of this class. A short description of the class members is given below: CheckingAccount Class Fields $- COST_PER_TRANSACTION = 0.05 : double $- INTEREST_RATE = 0.005 : double - hasOverdraft: bool Methods + «Constructor» CheckingAccount(balance =...
In this project you will implement the DataFrame class along with the all the methods that...
In this project you will implement the DataFrame class along with the all the methods that are represented in the class definition. DataFrame is a table with rows and columns – columns and rows have names associated with them also. For this project we will assume that all the values that are stored in the columns and rows are integers. After you have tested your class, you have to execute the main program that is also given below. DataFrame Class...
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will...
You shall implement six static methods in a class named BasicBioinformatics. Each of the methods will perform some analysis of data considered to be DNA. DNA shall be represented arrays of chars containing only the characters A, C, G and T. In addition to the six methods you will implement, six other methods exist in the class, which use Strings instead of char arrays to represent DNA. These other methods simply invoke the methods you are to implement, so all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT