-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDigitalLibraryManagement.java
More file actions
144 lines (123 loc) · 4.98 KB
/
DigitalLibraryManagement.java
File metadata and controls
144 lines (123 loc) · 4.98 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import java.util.*;
class Book {
String title;
String author;
boolean isIssued;
Book(String title, String author) {
this.title = title;
this.author = author;
this.isIssued = false;
}
}
class LibraryUser { // Renamed from User to LibraryUser
String name;
String email;
LibraryUser(String name, String email) {
this.name = name;
this.email = email;
}
}
class Library {
List<Book> books = new ArrayList<>();
List<LibraryUser> users = new ArrayList<>();
// Admin methods
void addBook(String title, String author) {
books.add(new Book(title, author));
System.out.println("Book added: " + title);
}
void removeBook(String title) {
books.removeIf(book -> book.title.equals(title));
System.out.println("Book removed: " + title);
}
void displayBooks() {
System.out.println("Available Books:");
for (Book book : books) {
System.out.println(book.title + " by " + book.author + (book.isIssued ? " (Issued)" : ""));
}
}
// User methods
void issueBook(String title) {
for (Book book : books) {
if (book.title.equals(title) && !book.isIssued) {
book.isIssued = true;
System.out.println("Book issued: " + title);
return;
}
}
System.out.println("Book not available: " + title);
}
void returnBook(String title) {
for (Book book : books) {
if (book.title.equals(title) && book.isIssued) {
book.isIssued = false;
System.out.println("Book returned: " + title);
return;
}
}
System.out.println("This book was not issued: " + title);
}
}
public class DigitalLibraryManagement {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Library library = new Library();
String action;
// Sample Data
library.addBook("1984", "George Orwell");
library.addBook("To Kill a Mockingbird", "Harper Lee");
System.out.println("Welcome to the Digital Library Management System!");
while (true) {
System.out.print("Are you an Admin or User? (admin/user/exit): ");
action = scanner.nextLine();
if (action.equalsIgnoreCase("admin")) {
while (true) {
System.out.print("Admin Options: (add/remove/display/exit): ");
String adminAction = scanner.nextLine();
if (adminAction.equalsIgnoreCase("add")) {
System.out.print("Enter book title: ");
String title = scanner.nextLine();
System.out.print("Enter book author: ");
String author = scanner.nextLine();
library.addBook(title, author);
} else if (adminAction.equalsIgnoreCase("remove")) {
System.out.print("Enter book title to remove: ");
String title = scanner.nextLine();
library.removeBook(title);
} else if (adminAction.equalsIgnoreCase("display")) {
library.displayBooks();
} else if (adminAction.equalsIgnoreCase("exit")) {
break;
} else {
System.out.println("Invalid option.");
}
}
} else if (action.equalsIgnoreCase("user")) {
while (true) {
System.out.print("User Options: (browse/issue/return/exit): ");
String userAction = scanner.nextLine();
if (userAction.equalsIgnoreCase("browse")) {
library.displayBooks();
} else if (userAction.equalsIgnoreCase("issue")) {
System.out.print("Enter book title to issue: ");
String title = scanner.nextLine();
library.issueBook(title);
} else if (userAction.equalsIgnoreCase("return")) {
System.out.print("Enter book title to return: ");
String title = scanner.nextLine();
library.returnBook(title);
} else if (userAction.equalsIgnoreCase("exit")) {
break;
} else {
System.out.println("Invalid option.");
}
}
} else if (action.equalsIgnoreCase("exit")) {
System.out.println("Exiting the system.");
break;
} else {
System.out.println("Invalid option.");
}
}
scanner.close();
}
}