0% found this document useful (0 votes)
19 views3 pages

Assignment No 2 Oop Lab

The document describes an assignment to model a library system using classes in Java. It involves creating an Author class with a method to return the author's name. A Book class should display book information and include an inner Review class with a method to display review comments. The task is to create these classes, an author, book, and review, and demonstrate it in the LibraryApp class by displaying the book information and review.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Assignment No 2 Oop Lab

The document describes an assignment to model a library system using classes in Java. It involves creating an Author class with a method to return the author's name. A Book class should display book information and include an inner Review class with a method to display review comments. The task is to create these classes, an author, book, and review, and demonstrate it in the LibraryApp class by displaying the book information and review.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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