Question 1
In a publication system, Author a1 contributes to a set of books. Author a2 also contributes to all the books contributed by a1 except for the second book, which a2 replaces with another book. Write a program that defines two classes Author and PublicationSystem. Define a copy constructor to create a2 from a1 such that changing the values of instance variables of either a2 or a1 does not affect the other one. The program accepts the name of author a2 and the new book contributed by a2 as input.
- Class
Authorhas/should have the following members.- Private instance variables
String nameandString[] booksto store the author name and the books contributed, respectively - Define the required constructor(s)
- Accessor methods
getName()andgetBook(int)to get the author name and the book at a specific index, respectively. - Mutator methods
setName(String)andsetBook(int, String)to set the author name and the book at a specific index, respectively.
- Private instance variables
- Class
PublicationSystemhas methodmainthat does the following.- Two objects of
Author,a1anda2, are created.a2is created usinga1. - The name of Author
a2and the second book contributed bya2are updated by taking the input. - Finally, the names of
a1anda2and the second book contributed bya1anda2are printed.
- Two objects of
What you have to do:
- Define a constructor to initialize the instance variables in class
Author. - Define a copy constructor to create a deep copy of another
Authorobject in classAuthor.