The scenario is that you are writing these for a library system that consists of multiple library locations and obviously, multiple books. Your task will not be all inclusive however, and you will only be responsible for a small part of it. Details:
Library: one variable to hold the location name - String and an array variable of Type Book to hold the books at that library location
Book: a variable to hold the Title of the book - String and a variable to hold the number of pages in the book, int.
Create appropriate constructors, get, and set methods for each class. Provide code to test it by creating two Book objects, set or change the title and number of pages. Provide code to test adding a book or books to a Library object.
As mentioned in the description above, I have implemented the following classes in Java.
Below is the code :
Library.java
public class Library {
private String name;
private Book books[];
Library(String name, Book books[]){
this.name = name;
this.books = books;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Book[] getBooks() {
return books;
}
public void setBooks(Book[] books) {
this.books = books;
}
}
Book.java :
public class Book {
private String title;
private int pages;
Book(String title, int pages){
this.title = title;
this.pages = pages;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
}
A main class to test the above two classes is below :
Main.java
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the details of the book :");
System.out.println("Enter the title");
String title = scanner.nextLine();
System.out.println("Enter the no. of pages : ");
int pages = scanner.nextInt();
Book bookOne = new Book(title,pages);
System.out.println("Details of Book One : ");
System.out.println("Title : " + bookOne.getTitle());
System.out.println("No. of Pages : " + bookOne.getPages());
scanner.nextLine();
System.out.println("---------------------------------");
System.out.println("Enter title of your choice to change the current title : ");
title = scanner.nextLine();
System.out.println("Enter the no. of pages of new book : ");
pages = scanner.nextInt();
bookOne.setTitle(title);
bookOne.setPages(pages);
System.out.println("New Details of Book One : ");
System.out.println("Title : " + bookOne.getTitle());
System.out.println("No. of Pages : " + bookOne.getPages());
scanner.nextLine();
System.out.println("---------------------------------");
System.out.println("Enter the details of the second book :");
System.out.println("Enter the title");
title = scanner.nextLine();
System.out.println("Enter the no. of pages : ");
pages = scanner.nextInt();
Book bookTwo = new Book(title,pages);
System.out.println("Details of Book Two : ");
System.out.println("Title : " + bookTwo.getTitle());
System.out.println("No. of Pages : " + bookTwo.getPages());
scanner.nextLine();
System.out.println("---------------------------------");
Book books[] = {bookOne,bookTwo};
Library library = new Library("New York Library", books);
System.out.println("Library's information :");
System.out.println("Name of Library : "+library.getName());
System.out.println("No of books in library : " + library.getBooks().length);
System.out.println("Information of Books inside library :");
System.out.println("---------------------------------");
for (int i = 0; i < library.getBooks().length; i++){
Book book = library.getBooks()[i];
System.out.println("Book Name : " + book.getTitle());
System.out.println("No. of Pages : " + book.getPages());
System.out.println("---------------------------------");
}
}
}
Sample Output Of Above Program :


"C:\Program Files\Java\jdk1.8.0_101\bin\java" ... Enter the details of the book : Enter the title The Picture of Dorian Gray Enter the no. of pages: 212 Details of Book One : Title : The Picture of Dorian Gray No. of Pages : 212 Enter title of your choice to change the current title : The Great Gatsby Enter the no. of pages of new book : 220 New Details of Book One : Title : The Great Gatsby No. of Pages : 220 Enter the details of the second book : Enter the title 1984 Enter the no. of pages : 165 Details of Book Two : Title : 1984 No. of Pages : 165 Library's information : Name of Library : New York Library No of books in library : 2 Information of Books inside library :
LULUNG LULU DUURD udrue 1IDIIY! Book Name: The Great Gatsby No. of Pages : 220 Book Name : 1984 No. of Pages : 165 Process finished with exit code 0
The scenario is that you are writing these for a library system that consists of multiple...