-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryManagementSystem.java
More file actions
93 lines (90 loc) · 3.88 KB
/
Copy pathLibraryManagementSystem.java
File metadata and controls
93 lines (90 loc) · 3.88 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package Library;
import java.util.ArrayList;
import java.util.Scanner;
// LibraryManagementSystem class with a simple text-based interface for interaction
public class LibraryManagementSystem {
public static void main(String[] args) {
Library library = new Library();
Scanner scanner = new Scanner(System.in);
boolean exit = false;
while (!exit) {
System.out.println("\nLibrary Management System:");
System.out.println("1. Add Book");
System.out.println("2. Remove Book");
System.out.println("3. Search Book by Title");
System.out.println("4. Search Book by Author");
System.out.println("5. Sort Books by Title");
System.out.println("6. Sort Books by Author");
System.out.println("7. Display Catalog");
System.out.println("8. Register Member");
System.out.println("9. Borrow Book");
System.out.println("10. Return Book");
System.out.println("11. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
System.out.print("Enter book title: ");
String title = scanner.nextLine();
System.out.print("Enter book author: ");
String author = scanner.nextLine();
library.addBook(title, author);
break;
case 2:
System.out.print("Enter book title to remove: ");
title = scanner.nextLine();
library.removeBook(title);
break;
case 3:
System.out.print("Enter book title to search: ");
title = scanner.nextLine();
ArrayList<Book> booksByTitle = library.searchBooksByTitle(title);
System.out.println("Search results:");
booksByTitle.forEach(System.out::println);
break;
case 4:
System.out.print("Enter author name to search: ");
author = scanner.nextLine();
ArrayList<Book> booksByAuthor = library.searchBooksByAuthor(author);
System.out.println("Search results:");
booksByAuthor.forEach(System.out::println);
break;
case 5:
library.sortBooksByTitle();
break;
case 6:
library.sortBooksByAuthor();
break;
case 7:
library.displayCatalog();
break;
case 8:
System.out.print("Enter member name: ");
String memberName = scanner.nextLine();
library.addMember(memberName);
break;
case 9:
System.out.print("Enter book title to borrow: ");
title = scanner.nextLine();
System.out.print("Enter member name: ");
memberName = scanner.nextLine();
library.borrowBook(title, memberName);
break;
case 10:
System.out.print("Enter book title to return: ");
title = scanner.nextLine();
System.out.print("Enter member name: ");
memberName = scanner.nextLine();
library.returnBook(title, memberName);
break;
case 11:
exit = true;
break;
default:
System.out.println("Invalid choice. Please try again.");
}
}
scanner.close();
}
}