A municipal library system manages a large collection of physical resources across several branches. To streamline operations, a digital cataloging system is being developed to track individual books and their availability.
Each book in the system has a title and a recorded page count. The system must also track whether the book is currently checked out to a member or available on the shelf. The books are managed within specific branches, each represented by a collection with a defined maximum capacity.
A developer has drafted the following Book and Library classes as part of the initial model:
public class Book {
private String title;
private int pages;
private boolean borrowed;
public Book(String t, int p) {
title = t;
pages = p;
borrowed = false;
}
public void setBorrowed(boolean status) {
borrowed = status;
}
public String getTitle() {
return title;
}
public int getPages() {
return pages;
}
}
public class Library {
private Book[] collection;
private String branchName;
public Library(String bName, int max) {
branchName = bName;
collection = new Book[max];
}
public void addBook(Book b, int index) {
if (index >= 0 && index < collection.length) {
collection[index] = b;
}
}
public String getBranchName() {
return branchName;
}
}
(a) the difference between an object’s state and its behaviors, using examples from the Book class.
(b) the advantage of using the private access modifier for the pages variable.