Answer to Question #201591 in Python for Sweatha

Question #201591

Problem Statement

Design a ‘book’ class with title, author, publisher, price and author’s royalty as instance

variables. Provide getter and setter properties for all variables. Also define a method

royalty() to calculate royalty amount author can expect to receive the following royalties:10%

of the retail price on the first 500 copies; 12.5% for the next 1,000 copies sold, then 15% for

all further copies sold.

Then design a new ‘ebook’ class inherited from ‘book’ class. Add ebook format (EPUB, PDF,

MOBI etc) as additional instance variable in inherited class.

Override royalty() method to deduct GST @12% on ebooks


1
Expert's answer
2021-06-01T05:13:33-0400
class Book:
    #constructor
    def __init__(self, title="", author="", publisher="", price=0, author_royality=0, copies_sold=0):
        self._title = title
        self._author = author
        self._publisher = publisher
        self._price = price
        self._author_royalty = author_royality
        self._copies_sold = copies_sold

    # getter methods
    def get_title(self):
        return self._title
    def get_author(self):
        return self._author
    def get_publisher(self):
        return self._publisher
    def get_price(self):
        return self._price
    def get_author_royalty(self):
        return self._author_royalty
    def get_copies_sold(self):
        return self._copies_sold

    # setter methods
    def set_title(self, x):
        self._title = x
    def set_author(self, x):
        self._author = x
    def set_publisher(self, x):
        self._publisher = x
    def set_price(self, x):
        self._price = x
    def set_author_royalty(self, x):
        self._author_royalty = x
    def set_copies_sold(self, x):
        self._copies_sold = x

    def royalty(self):
        if self.get_copies_sold() <= 500:
            return 0.1 * self._price
        elif self.get_copies_sold() <= 1500:
            return 0.125 * self._price
        else:
            return 0.15 * self._price


class Ebook(Book):
    def __init__(self, format = "", title="", author="", publisher="", price=0, author_royality=0, copies_sold=0):
        self.format = format;
        super().__init__(title, author, publisher, price, author_royality, copies_sold)


    def royalty(self):
        val = super().royalty()
        return val - (0.12 * val) # deduct 12% GST



def __main__():
    book = Ebook("pdf","","","",190,0,230)
    print(book.royalty())

if __name__ == "__main__":
    __main__()

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

Assignment Expert
01.06.21, 13:35

Dear Sweatha,

You're welcome. We are glad to be helpful. 

If you liked our service please press like-button beside answer field. Thank you!



Sweatha
01.06.21, 13:28

Thank you so much for your reply!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS