Question: Can someone please help me do this JAVA code. Lab 3 - Relationships among classes: Composition 3.0. Lab Goals - Write a class which is
Can someone please help me do this JAVA code.

Lab 3 - Relationships among classes: Composition 3.0. Lab Goals - Write a class which is composed of other class(es) - Use arrays in composition 3.1. Recall - Composition (has-a relationship): a class has an object of another class as a member. If we have a class called Exam that declares an instance member of the type Date, which is another class, we say that the class Exam has a relationship has- a with the class Date: public class Exam \{ private Date date; \} 3.2. Exercise 1 Consider the class Author below, which includes author name, email, a constructor that initializes the instance variables, getters and toString methods. Create a class Book which contains title, number of pages, and an author. Provide one constructor that initializes all the instance variables, getters and toString (example: "Java How to Program" by deitel [deitel@deitel.com], pp 1245) methods. Test your class. public class Author \{ private final String name; private final String email; public Author(String name, String email) \{ this.name = name; this. email = email; \} public String getName() \{ return name; \} public String getEmail() \{ return email; \} public String toString() \{ return getName( )+"["+ getEmail( )+"]"; \} 3.3. Exercise 2 Create a new class called Library which is composed of set of books. For that, the Library class will contain an array of books as an instance variable. The Library class will contain also the following: - An instance variable that save the number of books in the library - First constructor that takes a number representing the number of books and initializes the internal array of books according to that number (refer to addBook to see how to add more books) - Second constructor that takes an already filled array of books and assigns it to the instance variable and then we consider the library is full; we cannot add more books using addBooks - addBook method receives a new book as parameter and tries to add it if possible, otherwise prints an error message - findBook method receives a title of a book as parameter and returns the reference to that book if found, it returns null otherwise - tostring method returns a string compiled from the returned values of toString of the different books in the library Create a test program in which you test all the features of the class Library
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
