Answer to Question #282353 in Python for Rao

Question #282353

Construct a class named “Book” that assigns title, author and format as initial values.


Create a class named “Library” that extends “Book” and assigns available as initial value, a method named updateAvailability that updates availability of the book, and a method named “str” that returns the string representation of the class.

1
Expert's answer
2021-12-23T16:27:18-0500
class Book(object):
  # at the very beginning we need to create instance variables 
 # once we have it we have to create a constructor that allows a user to input instance variables *


    def __init__(self, title, author, year, publisher, cost):
        #instance fields found by Java to Python Converter:
        title = None
        author = None
        year = 0
        publisher = None
        cost = 0


        self.title=title
        self.author=author
        self.year=year
        self.publisher=publisher
        self.cost=cost


    #     then we have to create an accessor method for each of the instance variables created above to retun whatever 
    #     * has been inputted by the user
    #     


    def getTitle(self):
        return self.title


    def getAuthor(self):
        return self.author
    def getYear(self):
        return self.year
    def getPublisher(self):
        return self.publisher
    def getCost(self):
        return self.cost




    #     now we create a mutator method for each of the instance variables created above that allows a user to change
    #     * the state of the object.
    #     


    def setTitle(self, title):
        self.title=title


    def setAuthor(self, author):
        self.author=author
    def setYear(self, year):
        self.year=year
    def setPublisher(self, publisher):
        self.publisher=publisher
    def setCost(self, cost):
        self.cost=cost




    # the last part here is to create a toString method that returns all of the details of the book that has been inputted. *


    def toString(self):
        return "The details of the book are: " + self.title + ", " + self.author + ", " + self.year + ", " + self.publisher + ", " + self.cost

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS