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.
Author has/should have the following members.
String name and String[] books to store the author name and the books contributed, respectivelygetName() and getBook(int) to get the author name and the book at a specific index, respectively.setName(String) and setBook(int, String) to set the author name and the book at a specific index, respectively.PublicationSystem has method main that does the following.
Author, a1 and a2, are created. a2 is created using a1.a2 and the second book contributed by a2 are updated by taking the input.a1 and a2 and the second book contributed by a1 and a2 are printed.What you have to do:
Author.Author object in class Author.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 `Author` has/should have the following members. - Private instance variables `String name` and `String[] books` to store the author name and the books contributed, respectively - Define the required constructor(s) - Accessor methods `getName()` and `getBook(int)` to get the author name and the book at a specific index, respectively. - Mutator methods `setName(String)` and `setBook(int, String)` to set the author name and the book at a specific index, respectively. - Class `PublicationSystem` has method `main` that does the following. - Two objects of `Author`, `a1` and `a2`, are created. `a2` is created using `a1`. - The name of Author `a2` and the second book contributed by `a2` are updated by taking the input. - Finally, the names of `a1` and `a2` and the second book contributed by `a1` and `a2` are printed. 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 `Author` object in class `Author`. You are given two integers as input to form an object `r1` of type `Rectangle`, and two double values as input to form an object `r2` of type `Rectangle`. Complete the Java code to print the larger area among the areas of `r1` and `r2`. - Define a generic class `Rectangle` with the following members. - Instance variables `length` and `breadth` - Constructor to initialize the instance variables - Method `area()` that returns the area of a rectangle object - Method `compareArea()` that returns the larger area among that of `r1` and `r2`. - Class `Test` has method `main()`, and takes two integers and two double values as input to create two objects of `Rectangle` type. It then invokes the necessary methods and prints the larger area. What you have to do: - Define methods `area()` and `compareArea()` of class `Rectangle`. Complete the Java code that uses the concept of inheritance to demonstrate dynamic method dispatching. Class `WaterBody` has the following members: - Private instance variable `name` - Constructor to initialize `name` - Accessor method for `name` - Method `display` to display the text: `Inside an anonymous body of water` Classes `River` and `Lake` should be defined in such a way that any object of `River` or `Lake` can be assigned to a reference variable of type `WaterBody`. See the main method to understand the context. - For an object of `River`, method `display` should print the message `Inside river` followed by the name of the river. - For an object of `Lake`, method `display` should print the message `Inside lake` followed by the name of the lake. What you have to do: - Define an accessor method for `name` inside class `WaterBody` - Define method `display` inside class `WaterBody` - Define classes `River` and `Lake`