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

project (oop)

Uploaded by

eizaimtiaz835
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)
2 views

project (oop)

Uploaded by

eizaimtiaz835
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/ 13

Eiza Imtiaz(BSGSF23M33)

Zumaira Noor(BSGSF23A24)
Usman Ali(BSGSF23M20)
Topic:Library management System

Classes:(5)
1. Main class
2. Library class
3. Book class
4. User class
5. Transaction class
6. Electronics class
Bonus:Arraylist
1. Main class
main(String[] args):
Initializes Library, Book, User, Electronics, and Transaction.
Variables used:
o Library
o Book
o User
o Electronics
o Transaction.

Code:
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Date;
)public class Lbms_Eiza {
public static void main(String[] args) {
Library library = new Library();

2.Library:
 Variables:
 ArrayList<Book> books
 ArrayList<User> users,
 ArrayList<Electronics> electronics: Collections of library items.
 static int totalBooksIssued: Tracks issued books.
 Methods:
o Add methods:
o addBook(Book)
o addUser(User)
o addElectronics(Electronics).
o Get methods:
o getElectronics().
o Book management: issueBook(String, String),
returnBook(String).
Code:
import java.util.ArrayList;
public class Library {
ArrayList<Book> books = new ArrayList<>();
ArrayList<User> users = new ArrayList<>();
ArrayList<Electronics>electronics = new ArrayList<>();
private static int totalBooksIssued = 0;
public Library() {
this.books = new ArrayList<>();
this.users = new ArrayList<>();
this.electronics = new ArrayList<>();
}
public void addBook(Book book) {
books.add(book);
}
public void addUser(User user) {
users.add(user);
}
public void addElectronics(Electronics device) {
electronics.add(device);
}
public ArrayList<Electronics> getElectronics() {
return electronics;
}
public void issueBook(String isbn, String userId) {
for (Book book : books) {
if (book.getIsbn().equals(isbn) && book.isAvailable()) {
book.setAvailability(false);
System.out.println("Book issued successfully.");
return;
}
}
System.out.println("Book is not available.");
}
public void returnBook(String isbn) {
for (Book book : books) {
if (book.getIsbn().equals(isbn)) {
book.setAvailability(true);
System.out.println("Book returned successfully.");
return;
}
}
System.out.println("Book not found.");
}
}

3.Book:
 Variables:
 String title
 String author
 String isbn: Book details.
 boolean isIssued
 boolean isAvailable: Status of the book.
Methods:
Getters:
 getTitle()
 getAuthor()
 getIsbn()
 isAvailable()
 isIssued().
Setters:
setAvailability(boolean)
setIssued(boolean).
toString(): Provides a formatted string representation of the book.
Code:
public class Book {
private String title;
private String author;
private String isbn;
private boolean isIssued;
private boolean isAvailable;
public Book(String title, String author, String isbn) {
this.title = title;
this.author = author;
this.isbn = isbn;
this.isIssued = false;
this.isAvailable = true;
}
public String getTitle() {
return title;
}
public String getAuthor() {
return author;
}
public String getIsbn() {
return isbn;
}
public boolean isAvailable() {
return isAvailable;
}
public boolean isIssued() {
return isIssued;
}
public void setAvailability(boolean availability) {
isAvailable = availability;
}
public void setIssued(boolean issued) {
isIssued = issued;
}
@Override
public String toString() {
return "Title: " + title + ", Author: " + author + ", ISBN: " + isbn + ",
Issued: " + isIssued;
}
}

4.User:
 Variables:
 String name
 int userId: User details.
 static int totalUsers: Tracks the number of users.
 Book borrowed: Book currently borrowed by the user.
 Methods:
 Getters:
 getName()
 getUserId()
 getBorrowed().
 Setter:
 setBorrowed(Book).
 Static method: getTotalUsers().
 toString(): Provides a formatted string representation of the user.
Code:
public class User {
private String name;
private int userId;
private static int totalUsers = 0;
private Book borrowed;
public User(String name, int userId) {
this.name = name;
this.userId = userId;
this.borrowed = null;
totalUsers++;
}
public String getName() {
return name;
}
public int getUserId() {
return userId;
}
public Book getBorrowed() {
return borrowed;
}
public void setBorrowed(Book book) {
borrowed = book;

}
public static int getTotalUsers() { // Static method
return totalUsers;
}
@Override
public String toString() {
return "User ID: " + userId + ", Name: " + name;
}
}
5.Transaction:
Variables:
 String transactionId: Unique ID.
 User user: User involved in the transaction.
 Book book: Book involved in the transaction.
 Date issueDate
 Date returnDate: Transaction dates.
Methods:
  Getters: getTransactionId()
 getUser(),
 getBook().
  Setter:
 setReturnDate(Date).
  toString(): Provides a summary of the transaction.
Code:
import java.util.Date;
public class Transaction {
private String transactionId;
private User user;
private Book book;
private Date issueDate;
private Date returnDate;
public Transaction(String transactionId, User user, Book book, Date
issueDate) {
this.transactionId = transactionId;
this.user = user;
this.book = book;
this.issueDate = issueDate;
}
public void setReturnDate(Date returnDate) {
this.returnDate = returnDate;
}
public String getTransactionId() {
return transactionId;
}
public User getUser() {
return user;
}
public Book getBook() {
return book;
}
@Override
public String toString() {
return "User" + user + " Book: " + book+ "issueDate" + issueDate;
}

}
6.Electronics:
 Variables:
 String name
 String serialNumber
 boolean isAvailable: Availability status.
Methods:
 Getters:
 getName()
 getSerialNumber()
 isAvailable().
Setter:
setAvailable(boolean).
toString(): Provides a formatted string representation of the electronic item.
Code:
public class Electronics {
private String name;
private String serialNumber;
private boolean isAvailable;

public Electronics(String name, String serialNumber) {


this.name = name;
this.serialNumber = serialNumber;
this.isAvailable = true;
}
public String getName() {
return name;
}
public String getSerialNumber() {
return serialNumber;
}
public boolean isAvailable() {
return isAvailable;
}
public void setAvailable(boolean available) {
isAvailable = available;
}
@Override
public String toString() {
return "Name" + name + ", SerialNumber " + serialNumber;
}

}

You might also like