In: Computer Science
. Create a class called Book to represent a book. A Book should include four pieces of information as instance variables‐a book name, an ISBN number, an author name and a publisher. Your class should have a constructor that initializes the four instance variables. Provide a mutator method and accessor method (query method) for each instance variable. Inaddition, provide a method named getBookInfo that returns the description of the book as a String (the description should include all the information about the book). You should use this keyword in member methods and constructor. Write a test application named BookTest to create an array of object for 30 elements for class Book to demonstrate the class Book's capabilities.
CODE IN JAVA:
Book.java file:
public class Book {
private String bookName ;
private String ISBNNumber ;
private String authorName ;
private String publisher ;
public Book(String bookName, String iSBNNumber, String
authorName, String publisher) {
this.bookName = bookName;
ISBNNumber = iSBNNumber;
this.authorName = authorName;
this.publisher = publisher;
}
public String getBookName() {
return bookName;
}
public void setBookName(String bookName) {
this.bookName = bookName;
}
public String getISBNNumber() {
return ISBNNumber;
}
public void setISBNNumber(String iSBNNumber) {
ISBNNumber = iSBNNumber;
}
public String getAuthorName() {
return authorName;
}
public void setAuthorName(String authorName) {
this.authorName = authorName;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public String getBookInfo() {
return "Book [bookName=" + bookName
+ ", ISBNNumber=" + ISBNNumber + ", authorName=" + authorName
+ ", publisher=" + publisher + "]";
}
}
TestBook.java file:
import java.util.Scanner ;
public class TestBook {
public static void main(String[] args) {
Scanner sc = new
Scanner(System.in);
System.out.print("Enter book name :
");
String book = sc.nextLine();
System.out.print("Enter ISBN number
: ");
String ISBN = sc.nextLine();
System.out.print("Enter author name
: ");
String author =
sc.nextLine();
System.out.print("Enter publisher :
");
String publisher =
sc.nextLine();
Book b = new Book(book, ISBN,
author, publisher);
System.out.println(b.getBookInfo());
}
}
OUTPUT: