projects
projects
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();
Book book1 = new Book("How to Win Friends", "F. Scott Fitzgerald", "123456");
Book book2 = new Book("Art of not loving", "George", "789012");
Book book3 = new Book("To Kill a Mockingbird" , "Harper Lee" , "978800");
Book book4 = new Book("1984", "George Orwell", "9780451524935");
Book book5 = new Book("Pride and Prejudice", "Jane Austen", "9780141199078");
Book book6 = new Book("The Great Gatsby", "F. Scott Fitzgerald",
"9780743273565");
Book book7 = new Book("Moby Dick", "Herman Melville", "9781503280786");
Book book8 = new Book("War and Peace", "Leo Tolstoy", "9781400079988");
Book book9 = new Book("The Catcher in the Rye", "J.D. Salinger",
"9780316769488");
Book book10 = new Book("Brave New World", "Aldous Huxley", "9780060850524");
Book book11 = new Book("The Hobbit", "J.R.R. Tolkien", "9780547928227");
library.addBook(book1);
library.addBook(book2);
library.addBook(book3);
library.addBook(book4);
library.addBook(book5);
library.addBook(book6);
library.addBook(book7);
library.addBook(book8);
library.addBook(book9);
library.addBook(book10);
library.addBook(book11);
System.out.println(library.books);
// Adding users
User user1 = new User("Alice", 1);
User user2 = new User("Bob", 2);
User user3 = new User("Charlie", 3);
User user4 = new User("David", 4);
User user5 = new User("Eve", 5);
User user6 = new User("Frank", 6);
User user7 = new User("Grace", 7);
User user8 = new User("Hannah", 8);
User user9 = new User("Ivy", 9);
User user10 = new User("Jack", 10);
// Adding all users to the library
library.addUser(user1);
library.addUser(user2);
library.addUser(user3);
library.addUser(user4);
library.addUser(user5);
library.addUser(user6);
library.addUser(user7);
library.addUser(user8);
library.addUser(user9);
library.addUser(user10);
System.out.println(library.users);
//electronics
Electronics E1 = new Electronics("Laptop", "E001");
Electronics E2 = new Electronics("Tablet", "E002");
library.addElectronics(E1);
library.addElectronics(E2);
System.out.println(library.electronics);
// Transaction
Transaction transaction = new Transaction("T001", user1, book1, new Date());
System.out.println("Transaction ID " + transaction.getTransactionId());
System.out.println(transaction.getUser());
System.out.println(transaction.getBook());
System.out.println(transaction.toString());
// Command loop
Scanner scanner = new Scanner(System.in);
String command;
while (true) {
// Display menu
System.out.println("\nWelcome to the Library System!");
System.out.println("Available commands:");
System.out.println("1 - Borrow a book");
System.out.println("2 - Return a book");
System.out.println("3 - Add a new book");
System.out.println("4 - Add a new user");
System.out.println("5 - View all books");
System.out.println("6 - Exit");
System.out.print("Enter your choice: ");
switch (option) {
case 1: // Borrow a book
System.out.print("Enter user ID: ");
int borrowerId = scanner.nextInt();
scanner.nextLine(); // Clear input buffer
System.out.print("Enter book ISBN: ");
String borrowIsbn = scanner.nextLine();
if (borrowedBook == null) {
System.out.println("Book not found.");
} else if (!borrowedBook.isAvailable()) {
System.out.println("Book is already borrowed.");
} else {
borrowedBook.setIssued(true);
borrowedBook.setAvailability(false);
System.out.println("You have successfully borrowed the
book: " + borrowedBook.getTitle());
}
break;
case 2: // Return a book
System.out.print("Enter book ISBN: ");
String returnIsbn = scanner.nextLine();
if (returnedBook == null) {
System.out.println("Book not found.");
} else if (returnedBook.isAvailable()) {
System.out.println("Book is not currently borrowed.");
} else {
returnedBook.setIssued(false);
returnedBook.setAvailability(true);
System.out.println("You have successfully returned the
book: " + returnedBook.getTitle());
}
break;
case 6: // Exit
System.out.println("Exiting the Library System. Goodbye!");
scanner.close();
System.exit(0);
}
//transaction
import java.util.Date;
public class Transaction {
private String transactionId;
private User user;
private Book book;
private Date issueDate;
private Date returnDate;
}
//electronics
public class Electronics {
private String name;
private String serialNumber;
private boolean isAvailable;