A class called Book is designed to model a book written by one author. It contains: • Four private instance variables: name (String), author (of the class Author you have just created, assume that a book has one and only one author), price (double), and qty (int); • An __init__() to initialize the name, author, price, and qty with the given values; • Getters/Setters: getName(), getAuthor(), getPrice(), setPrice(), getQty(), setQty(). • __str__() method that returns printable string of that object with the following format: "Book[name=?,Author[name=?,email=?,gender=?],price=?,qty=?". You should reuse Author’s __str__(). Write the Book class (which uses the Author class written earlier). Also write a test driver codeto test all the methods in the class Book. Take Note that you have to construct an instance of Author before you can construct an instance of Book. E.g., ahTeck = Author("Tan Ah Teck", "ahteck@nowhere.com", 'm') # Test the constructor print(ahTeck) # Test __str__() dummyBook = Book("Java for dummy", ahTeck, 19.95, 99) # Test Book's Constructor print(dummyBook); # Test __str__() # Test Getters and Setters dummyBook.setPrice(29.95) dummyBook.setQty(28) print ("name is: " , dummyBook.getName()) print ("price is: " , dummyBook.getPrice()) print ("qty is: " , dummyBook.getQty()) print ("Author is: " , dummyBook.getAuthor()) # Author's __str__() print ("Author's name is: " , dummyBook.getAuthor().getName()) print ("Author's email is: " , dummyBook.getAuthor().getEmail()) Take note that both Book and Author classes have a variable called name. However, it can be differentiated via the referencing instance. For a Book instance says aBook, aBook.name refers to the name of the book; whereas for an Author's instance say auAuthor, anAuthor.name refers to the name of the author. There is no need (and not recommended) to call the variables bookName and authorName. Save your code as book.py.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

A class called Book is designed to model a book written by one author. It contains:
• Four private instance variables: name (String), author (of the class Author you have just
created, assume that a book has one and only one author), price (double), and qty (int);
• An __init__() to initialize the name, author, price, and qty with the given values;
• Getters/Setters: getName(), getAuthor(), getPrice(), setPrice(), getQty(), setQty().
• __str__() method that returns printable string of that object with the following format:
"Book[name=?,Author[name=?,email=?,gender=?],price=?,qty=?".
You should reuse Author’s __str__().
Write the Book class (which uses the Author class written earlier). Also write a test driver
codeto test all the methods in the class Book. Take Note that you have to construct an instance
of Author before you can construct an instance of Book. E.g.,
ahTeck = Author("Tan Ah Teck", "ahteck@nowhere.com", 'm') # Test the constructor
print(ahTeck) # Test __str__()
dummyBook = Book("Java for dummy", ahTeck, 19.95, 99) # Test Book's Constructor
print(dummyBook); # Test __str__()

# Test Getters and Setters
dummyBook.setPrice(29.95)
dummyBook.setQty(28)
print ("name is: " , dummyBook.getName())
print ("price is: " , dummyBook.getPrice())
print ("qty is: " , dummyBook.getQty())
print ("Author is: " , dummyBook.getAuthor()) # Author's __str__()
print ("Author's name is: " , dummyBook.getAuthor().getName())
print ("Author's email is: " , dummyBook.getAuthor().getEmail())

Take note that both Book and Author classes have a variable called name. However, it can be
differentiated via the referencing instance. For a Book instance says aBook, aBook.name refers
to the name of the book; whereas for an Author's instance say auAuthor, anAuthor.name refers
to the name of the author. There is no need (and not recommended) to call the variables
bookName and authorName.

Save your code as book.py.

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY