📌 Problem Statement:
Create a Java program for managing library books. Use a Book class with attributes: bookId,
title, author, and availability. Allow adding, viewing, and checking availability of books using
an array of objects.
🎯 Objective:
To implement arrays of objects and use basic class design to model a library system.
🧠 Class Structure:
class Book {
int bookId;
String title;
String author;
boolean isAvailable;
Book(int bookId, String title, String author) {
[Link] = bookId;
[Link] = title;
[Link] = author;
[Link] = true;
void display() {
[Link](bookId + " | " + title + " | " + author + " | " + (isAvailable ? "Available"
: "Not Available"));
Main Program:
import [Link];
public class LibrarySystem {
public static void main(String[] args) {
Scanner sc = new Scanner([Link]);
Book[] books = new Book[3];
int count = 0;
while (true) {
[Link]("\n1. Add Book\n2. View Books\n3. Exit");
int choice = [Link]();
[Link]();
switch (choice) {
case 1:
if (count < [Link]) {
[Link]("Enter Book ID: ");
int id = [Link]();
[Link]();
[Link]("Enter Title: ");
String title = [Link]();
[Link]("Enter Author: ");
String author = [Link]();
books[count++] = new Book(id, title, author);
} else {
[Link]("Library full!");
break;
case 2:
for (int i = 0; i < count; i++) {
books[i].display();
}
break;
case 3:
return;