-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibraryManagementSystem.java
66 lines (60 loc) · 2.49 KB
/
LibraryManagementSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.Scanner;
public class LibraryManagementSystem {
public static void main(String[] args) {
Library library = new Library();
Scanner scanner = new Scanner(System.in);
// Sample data
library.addBook(new Book(1, "The Great Gatsby", "F. Scott Fitzgerald", false));
library.addBook(new Book(2, "1984", "George Orwell", false));
library.addBook(new Book(3, "To Kill a Mockingbird", "Harper Lee", false));
User user = new User(1, "Marcos");
library.addUser(user);
int choice;
do {
System.out.println("\n--- Library Management System ---");
System.out.println("1. Display All Books");
System.out.println("2. Search for a Book");
System.out.println("3. Borrow a Book");
System.out.println("4. Return a Book");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
library.displayBooks();
break;
case 2:
System.out.print("Enter book title: ");
String title = scanner.nextLine();
Book book = library.searchBook(title);
if (book != null) {
System.out.println("Book found: " + book);
}
break;
case 3:
System.out.print("Enter book title to borrow: ");
title = scanner.nextLine();
book = library.searchBook(title);
if (book != null) {
user.BorrowBook(book);
}
break;
case 4:
System.out.print("Enter book title to return: ");
title = scanner.nextLine();
book = library.searchBook(title);
if (book != null) {
user.ReturnBook(book);
}
break;
case 5:
System.out.println("Exiting... Goodbye!");
break;
default:
System.out.println("Invalid choice. Try again.");
}
} while (choice != 5);
scanner.close();
}
}