Library Book Status
A school library keeps a simple record for each book: the title and whether that book is currently checked out. When a student asks about a book, the desk wants to show a short message explaining its status.
Your task is to use a small Book class and return a message in one of these two formats:
"Title is available" if the book is not checked out, or "Title is checked out" if it is.
For example, if the title is "Math Club" and the checked-out value is false, the answer should be "Math Club is available". If the title is "Science Lab" and the checked-out value is true, the answer should be "Science Lab is checked out".
This is an easy object-oriented exercise where the class stores the book's state, and one of its methods turns that state into a readable message.
Example Input & Output
The title should stay intact inside the final message.
A checked-out book should return the checked-out message.
A book that is not checked out should be marked available.
Algorithm Flow

Solution Approach
This problem is a nice example of using an object to hold state and then letting the object decide how to describe itself.
The Book class can store two fields: the title and the checked-out flag. Once those are saved in the constructor, the class can expose a method like getStatusMessage() that returns the correct sentence based on the boolean value.
The main logic sits naturally inside the class:
Then the outer solution method only needs to create the object and call that method. This keeps the decision about the book's message inside the Book class, which is the most object-oriented part of the exercise.
You could also use a ternary operator instead of an if statement, and that would still be correct. The important idea is not the exact syntax. It is the pattern of giving a class both the data and the behavior that depends on that data.
The runtime is constant, O(1), because each call builds one object and returns one short string. The challenge is mainly about class structure and method placement, which is exactly why it fits a Java OOP category so well.
Best Answers
class Book {
private String title;
private boolean checkedOut;
public Book(String title, boolean checkedOut) {
this.title = title;
this.checkedOut = checkedOut;
}
public String getStatusMessage() {
if (checkedOut) {
return title + " is checked out";
}
return title + " is available";
}
}
class Solution {
public static String checkBookStatus(String title, boolean checkedOut) {
return new Book(title, checkedOut).getStatusMessage();
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
