Question: Make sure to put the main section of your code in the following if block: # Type code for classes here if __name__ == __main__:
Make sure to put the main section of your code in the following if block:
# Type code for classes here if __name__ == "__main__": # Type main section of code here
(1) Build the Book class with the following specifications:
Attributes
title (str)
author (str)
publisher (str)
copyright (str)
Create a constructor that has 4 parameters (in addition to self). Set each of the constructor parameters to the default value (empty string)
Define a __str__() method to print a Book like the following
Title: Java Software Solutions Author: Lewis & Loftus Publisher: Addison-Wesley Copyright: 2012
(2) In the main section of your code, read in the file books.txt. Create a list called library. Create books from the file and add them to the library.
(3) Print the library as follows.
The library has 3 books:
Title: Java Software Solutions
Author: Lewis & Loftus
Publisher: Addison-Wesley Copyright: 2012
Title: Faces in Time
Author: Lewis Aleman
Publisher: Megalodon Entertainment Copyright: 2010
Title: Purple Cow
Author: Seth Godin
Publisher: Portfolio Copyright: 2002
Make sure to put the main section of your code in the following if block:
# Type code for classes here if __name__ == "__main__": # Type main section of code here
(1) Build the Book class with the following specifications:
Attributes
title (str)
author (str)
publisher (str)
copyright (str)
Create a constructor that has 4 parameters (in addition to self). Set each of the constructor parameters to the default value (empty string)
Define a __str__() method to print a Book like the following
Title: Java Software Solutions Author: Lewis & Loftus Publisher: Addison-Wesley Copyright: 2012
(2) In the main section of your code, read in the file books.txt. Create a list called library. Create books from the file and add them to the library.
(3) Print the library as follows.
The library has 3 books:
Title: Java Software Solutions
Author: Lewis & Loftus
Publisher: Addison-Wesley Copyright: 2012
Title: Faces in Time
Author: Lewis Aleman
Publisher: Megalodon Entertainment Copyright: 2010
Title: Purple Cow
Author: Seth Godin
Publisher: Portfolio Copyright: 2002
Books.txt:
Java Software Solutions Lewis & Loftus Addison-Wesley 2012 Faces in Time Lewis Aleman Megalodon Entertainment 2010 Purple Cow Seth Godin Portfolio 2002 The interesting life of Trish Duce Trish Duce Addison-Wesley 2017
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
