You are on page 1of 3

ASSIGNMENT NO 2 : OOP LAB

In a library system, you have the classes Author and Book. The Author class has a
method getName() to retrieve the author's name, and the Book class has a
method displayBookInfo() to display the book's title and author.

Now, you need to implement a book review system using an inner class called
Review inside the Book class. The Review class should have a method
displayReview() to display the review comments.

Create a Java program that models this library system, and demonstrate it by
creating an author, a book, and a review for the book in the LibraryApp class.
Display the book information and the review.

SOLUTION :

class Author {

private String authorName;

Author(String authorName) {

this.authorName = authorName;

public String getAuthorName() {

return authorName;

class Book {

private String title;

private Author author;


Book(String title, Author author) {

this.title = title;

this.author = author;

public void displayInfo() {

System.out.println("BOOK Title: " + title);

System.out.println("Author Name: " + author.getAuthorName());

class Review {

String review;

Review(String review) {

this.review = review;

public void displayReview() {

System.out.println("Book Review: " + review);

public class LibraryApp {


public static void main(String[] args) {

Author author = new Author("Syeda Rutab Aziz");

Book book = new Book("My Perspectives", author);

Book.Review review = book.new Review("This book is fantastic and worth


reading");

book.displayInfo();

review.displayReview();

OUTPUT :

BOOK Title: My Perspectives

Author Name: Syeda Rutab Aziz

Book Review: This book is fantastic and worth reading

You might also like