Question: Update the comments on the code below and create a Javadoc. public class Book { private String bookId; private String title; private String author; private

Update the comments on the code below and create a Javadoc.
public class Book {
private String bookId;
private String title;
private String author;
private boolean availability;
private String borrower;
// Default constructor
public Book(){
this.bookId ="";
this.title ="";
this.author ="";
this.availability = true;
this.borrower ="";
}
// Parameterized constructor
public Book(String bookId, String title, String author, boolean availability){
setBookId(bookId);
setTitle(title);
setAuthor(author);
this.availability = availability;
this.borrower ="";
}
// Getter and Setter for bookId
public String getBookId(){
return bookId;
}
public void setBookId(String bookId){
if (bookId == null || bookId.isEmpty()){
throw new IllegalArgumentException("Book ID cannot be null or empty");
}
this.bookId = bookId;
}
// Getter and Setter for title
public String getTitle(){
return title;
}
public void setTitle(String title){
if (title == null || title.isEmpty()){
throw new IllegalArgumentException("Title cannot be null or empty");
}
this.title = title;
}
// Getter and Setter for author
public String getAuthor(){
return author;
}
public void setAuthor(String author){
if (author == null || author.isEmpty()){
throw new IllegalArgumentException("Author cannot be null or empty");
}
this.author = author;
}
// Getter and Setter for availability
public boolean isAvailable(){
return availability;
}
public void setAvailability(boolean availability){
this.availability = availability;
}
// Getter and Setter for borrower
public String getBorrower(){
return borrower;
}
public void setBorrower(String borrower){
this.borrower = borrower;
}
@Override
public String toString(){
return "Book ID: "+ bookId +", Title: "+ title +", Author: "+ author +
", Available: "+ availability +", Borrower: "+ borrower;
}
}
LibraryManagementSystem Class
import java.util.Scanner;
public class LibraryManagementSystem {
private Book[] books;
private int bookCount;
// Constructor
public LibraryManagementSystem(int capacity){
books = new Book[capacity];
bookCount =0;
}
// Add a new book
public void addBook(String bookId, String title, String author, boolean availability){
for (int i =0; i < bookCount; i++){
if (books[i].getBookId().equals(bookId)){
System.out.println("Book ID already exists.");
return;
}
}
books[bookCount++]= new Book(bookId, title, author, availability);
System.out.println("Book added successfully.");
}
// Display all books
public void displayAllBooks(){
for (int i =0; i < bookCount; i++){
System.out.println(books[i]);
}
}
// Search for a book
public void searchBook(String bookId){
for (int i =0; i < bookCount; i++){
if (books[i].getBookId().equals(bookId)){
System.out.println(books[i]);
return;
}
}
System.out.println("Book not found.");
}
// Borrow a book
public void borrowBook(String bookId, String borrower){
for (int i =0; i < bookCount; i++){
if (books[i].getBookId().equals(bookId)){
if (books[i].isAvailable()){
books[i].setAvailability(false);
books[i].setBorrower(borrower);
System.out.println("Book borrowed successfully.");
} else {
System.out.println("Book is currently unavailable.");
}
return;
}
}
System.out.println("Book not found.");
}
// Return a book
public void returnBook(String bookId){
for (int i =0; i < bookCount; i++){
if (books[i].getBookId().equals(bookId)){
if (!books[i].isAvailable()){
books[i].setAvailability(true);
books[i].setBorrower("");
System.out.println("Book returned successfully.");
} else {
System.out.println("Book was not borrowed.");
}
return;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!