0% found this document useful (0 votes)
0 views3 pages

Library Book Inventory

The document outlines a Java program for managing library books using a Book class with attributes for bookId, title, author, and availability. It includes functionality to add, view, and check the availability of books through an array of Book objects. The main program utilizes a loop for user interaction, allowing the addition of books until the array limit is reached, and displays the current books in the library.

Uploaded by

anair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views3 pages

Library Book Inventory

The document outlines a Java program for managing library books using a Book class with attributes for bookId, title, author, and availability. It includes functionality to add, view, and check the availability of books through an array of Book objects. The main program utilizes a loop for user interaction, allowing the addition of books until the array limit is reached, and displays the current books in the library.

Uploaded by

anair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

📌 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) {

this.bookId = bookId;

this.title = title;

this.author = author;

this.isAvailable = true;

void display() {

System.out.println(bookId + " | " + title + " | " + author + " | " + (isAvailable ? "Available"
: "Not Available"));

Main Program:

import java.util.Scanner;

public class LibrarySystem {

public static void main(String[] args) {


Scanner sc = new Scanner(System.in);

Book[] books = new Book[3];

int count = 0;

while (true) {

System.out.println("\n1. Add Book\n2. View Books\n3. Exit");

int choice = sc.nextInt();

sc.nextLine();

switch (choice) {

case 1:

if (count < books.length) {

System.out.print("Enter Book ID: ");

int id = sc.nextInt();

sc.nextLine();

System.out.print("Enter Title: ");

String title = sc.nextLine();

System.out.print("Enter Author: ");

String author = sc.nextLine();

books[count++] = new Book(id, title, author);

} else {

System.out.println("Library full!");

break;

case 2:

for (int i = 0; i < count; i++) {

books[i].display();

}
break;

case 3:

return;

You might also like