0% found this document useful (0 votes)
4 views

java adi

The document outlines an experiment for a Java-based book management system, detailing the creation of classes for books, members, and libraries. It includes Java code for managing book issuance and returns, as well as methods for adding books and members to the library. The main function demonstrates the functionality of the system by adding books and members, issuing books, and displaying the status of the books.

Uploaded by

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

java adi

The document outlines an experiment for a Java-based book management system, detailing the creation of classes for books, members, and libraries. It includes Java code for managing book issuance and returns, as well as methods for adding books and members to the library. The main function demonstrates the functionality of the system by adding books and members, issuing books, and displaying the status of the books.

Uploaded by

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

DEPARTMENT OF

COMPUTER SCIENCE & ENGINEERING

Experiment 1.1
Student Name: aditya UID: 23bet10090
Branch:BE IT Section/Group: 818A
Semester: 4TH Date of Performance:21JAN
Subject Name:JAVA Subject Code:23ITH202

1. Aim: Create a books managing system where relationship between

books,member,libracy

2. Objective: create book ,member,libracy class

Add id for books and member

3. Java Code:

class Book {

String id, name;

boolean issued;

public Book(String id, String name) {

this.id = id;

this.name = name;

this.issued = false;

boolean isAvailable() {

return !issued;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

void issue() {

issued = true;

void returnBook() {

issued = false;

public String toString() {

return name + " (ID: " + id + ")";

class Member {

String id, name;

Book issuedBook;

public Member(String id, String name) {

this.id = id;

this.name = name;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

this.issuedBook = null;

public void issueBook(Book book) {

if (book.isAvailable()) {

book.issue();

issuedBook = book;

System.out.println(book + " issued to " + name);

} else {

System.out.println(book + " is already issued.");

public void returnBook() {

if (issuedBook != null) {

issuedBook.returnBook();

System.out.println(issuedBook + " returned by " + name);

issuedBook = null;

} else {

System.out.println(name + " has no book to return.");

}
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

public String toString() {

return name + " (ID: " + id + ")";

class Library {

Book[] books = new Book[10];

Member[] members = new Member[10];

int bookCount = 0, memberCount = 0;

void addBook(Book book) {

books[bookCount++] = book;

void addMember(Member member) {

members[memberCount++] = member;

void issueBookToAllMembers() {

for (Member member : members) {

if (member != null) {

for (Book book : books) {


DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

if (book != null && book.isAvailable()) {

member.issueBook(book);

break;}

void viewBooks() {

for (Book book : books) {

if (book != null) {

System.out.println(book + (book.isAvailable() ? " - Available" :

" - Issued"));

public class LibrarySystem {

public static void main(String[] args) {

Library library = new Library();

library.addBook(new Book("b001", "Java Programming"));

library.addBook(new Book("b002", "Data Structures"));

library.addBook(new Book("b003", "Algorithms"));

library.addMember(new Member("m001", "Aditya"));

library.addMember(new Member("m002", "Sam"));

library.addMember(new Member("m003", "Amrit"));

library.viewBooks();
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

library.issueBookToAllMembers();

library.viewBooks();

for (Member member : library.members) {

if (member != null) {

member.returnBook();

library.viewBooks();

4. Output:
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING

You might also like