Answer to Question #295816 in Python for Ayush

Question #295816

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, 1000 copies sold, then 15% for all further other copies sold.


Then design a new 'ebook' class inherited from 'book'class.Add ebook format (EPUB, PDF, MOBI etc) and additional instance variable in inherited class.


override method to deduct GST @12% on ebooks

1
Expert's answer
2022-02-10T00:19:03-0500
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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS