Answer to Question #201611 in Python for Sweatha

Question #201611

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-02T02:57:50-0400
class book:
    def __init__(self, title, author, publisher, price, royalty):
        self.title = title
        self.author = author
        self.publisher = publisher
        self.price = price
        self.royalty = royalty

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

    def set_author(self, author):
        self.author = author

    def set_publisher(self, publisher):
        self.publisher = publisher

    def set_price(self, price):
        self.price = price

    def set_royalty(self, royalty):
        self.royalty = royalty

    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_royalty(self):
        return self.royalty

    def royalty(self, copies):
        if copies <= 500:
            return 0.1 * self.price * copies
        elif 500 < copies <= 1500:
            return 0.1 * self.price * 500 + 0.125 * self.price * (copies - 500)
        elif 1500 < copies:
            return 0.1 * self.price * 500 + 0.125 * self.price * 1000 + 0.15 * self.price * (copies - 1500)


class ebook(book):
    def __init__(self, title, author, publisher, price, royalty, format):
        super().__init__(title, author, publisher, price, royalty)
        self.format = format

    def set_format(self, format):
        self.format = format

    def get_format(self):
        return self.format

    def royalty(self, copies):
        return 0.88 * super().royalty(copies)

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

Sweatha
02.06.21, 11:35

Thank you so much for the reply!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS