-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMS.java
More file actions
406 lines (371 loc) · 14.5 KB
/
Copy pathLMS.java
File metadata and controls
406 lines (371 loc) · 14.5 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
import java.util.ArrayList;
import java.util.Scanner;
public class LMS
{
static final int MAX_BOOKS = 100;
public static ArrayList<Integer> bookIDs = new ArrayList<>();
public static ArrayList<String> titles = new ArrayList<>();
public static ArrayList<String> authors = new ArrayList<>();
public static ArrayList<Integer> totalQuantities = new ArrayList<>(); // Total copies owned by library
public static ArrayList<Integer> availableQuantities = new ArrayList<>(); // Copies available to borrow
public static ArrayList<String> bookStatus = new ArrayList<>(); // e.g., "Good", "Damaged"
private static void displayMainMenu()
{
System.out.println("\n=============================================");
System.out.println(" MAIN MENU");
System.out.println("=============================================");
System.out.println("1. Books Management");
System.out.println("2. Study Room Management");
System.out.println("3. Membership Management");
System.out.println("4. Exit System");
}
private static void bookMenu()
{
System.out.println("\n--- Books Management Menu ---");
System.out.println("1. Add a new book");
System.out.println("2. Remove a book");
System.out.println("3. Search book by ID or Author");
System.out.println("4. Display all available books");
System.out.println("5. Issue a book");
System.out.println("6. Return a book");
System.out.println("7. Update book quantity / status");
System.out.println("8. Show all issued books");
System.out.println("9. Back to Main Menu");
}
private static void roomMenu()
{
System.out.println("\n--- Study Room Management Menu ---");
System.out.println("1. Show Available Study Rooms");
System.out.println("2. Reserve a study room");
System.out.println("3. Cancel Reservation");
System.out.println("4. Check Reservation Status");
System.out.println("5. Back to Main Menu");
}
private static void memberMenu()
{
System.out.println("\n--- Membership Management Menu ---");
System.out.println("1. Register a new member");
System.out.println("2. Display all members");
System.out.println("3. Search members by ID or Name");
System.out.println("4. View issued books by a member");
System.out.println("5. Remove member");
System.out.println("6. Back to Main Menu");
}
public static void addBook(Scanner input)
{
System.out.println("\n--- Add a New Book ---");
System.out.print("Enter new Book ID: ");
int id = input.nextInt();
bookIDs.add(id);
input.nextLine();
System.out.print("Enter Book Title: ");
String title = input.nextLine();
titles.add(title);
System.out.print("Enter Author Name: ");
String author = input.nextLine();
authors.add(author);
System.out.print("Enter Total Quantity purchased: ");
int total = input.nextInt();
totalQuantities.add(total);
input.nextLine();
System.out.println("-> Collected details for: " + title + " (ID: " + id + ", Qty: " + total + ") by "+author);
}
public static void removeBook(Scanner input)
{
System.out.println("\n--- Remove a Book ---");
System.out.print("Enter Book ID to remove: ");
int id = input.nextInt();
input.nextLine();
System.out.println("-> Attempting to remove book with ID: " + id);
for (int i=0; i < bookIDs.size(); i++){
if (bookIDs.get(i)==id){
bookIDs.remove(i);
titles.remove(i);
authors.remove(i);
totalQuantities.remove(i);
System.out.println("Book Removed Successfully");
}
}
}
public static void searchBook(Scanner input)
{
System.out.println("\n--- Search Book ---");
System.out.println("Search by (1) ID or (2) Author?");
System.out.print("Enter option (1 or 2): ");
int type = input.nextInt();
input.nextLine();
if (type == 1)
{
System.out.print("Enter Book ID: ");
int id = input.nextInt();
input.nextLine();
System.out.println("-> Searching for book with ID: " + id);
}
else if (type == 2)
{
System.out.print("Enter Author Name: ");
String authorName = input.nextLine();
System.out.println("-> Searching for books by author: " + authorName);
} else
{
System.out.println("[!] Invalid search option.");
}
}
public static void displayAvailableBooks()
{
System.out.println("-> Functionality to display all available books.");
}
public static void issueBook(Scanner input)
{
System.out.println("\n--- Issue a Book ---");
System.out.print("Enter Book ID to issue: ");
int bookId = input.nextInt();
System.out.print("Enter Member ID: ");
int memberId = input.nextInt();
input.nextLine();
System.out.print("Enter today's Date (YYYY-MM-DD): ");
String date = input.nextLine();
System.out.println("-> Attempting to issue Book " + bookId + " to Member " + memberId + " on " + date);
}
public static void returnBook(Scanner input)
{
System.out.println("\n--- Return a Book ---");
System.out.print("Enter Book ID to return: ");
int bookId = input.nextInt();
System.out.print("Enter Member ID who is returning the book: ");
int memberId = input.nextInt();
input.nextLine();
System.out.println("-> Attempting to return Book " + bookId + " from Member " + memberId);
}
public static void updateBookDetails(Scanner input)
{
System.out.println("\n--- Update Book Details ---");
System.out.print("Enter Book ID to update: ");
int id = input.nextInt();
input.nextLine();
System.out.println("1. Update Total Quantity");
System.out.println("2. Update Book Status (e.g., Damaged, Lost)");
System.out.print("Enter update choice (1 or 2): ");
int choice = input.nextInt();
input.nextLine();
if (choice == 1)
{
System.out.print("Enter NEW total quantity: ");
int newTotal = input.nextInt();
input.nextLine();
System.out.println("-> Updating quantity of Book " + id + " to " + newTotal);
}
else if (choice == 2)
{
System.out.print("Enter new status (e.g., Damaged, Good): ");
String newStatus = input.nextLine();
System.out.println("-> Updating status of Book " + id + " to " + newStatus);
}
}
public static void showAllIssuedBooks()
{
System.out.println("-> Functionality to show all issued books (transaction log).");
}
public static void backToMainMenu()
{
System.out.println("-> Returning to Main Menu.");
}
public static void showAvailableRooms()
{
System.out.println("\n--- Available Study Rooms (Mock Data) ---");
System.out.printf("%-10s | %-15s | %-15s%n", "Room No.", "Status", "Reserved By");
System.out.println("---------------------------------------------");
}
public static void reserveRoom()
{
System.out.println("-> Functionality to reserve a study room.");
}
public static void cancelReservation()
{
System.out.println("-> Functionality to cancel a reservation.");
}
public static void checkReservationStatus(Scanner scanner)
{
System.out.println("-> Functionality to check reservation status.");
}
public static void registerNewMember(Scanner input)
{
System.out.println("\n--- Register a New Member ---");
System.out.print("Enter Member Name: ");
String name = input.nextLine();
// Mocking automatic ID generation
int newId = 5003;
System.out.println("\n[+] Member '" + name + "' registered successfully.");
System.out.println("[*] Assigned Member ID: " + newId);
}
public static void displayAllMembers()
{
System.out.println("\n--- All Registered Members (Mock Data) ---");
System.out.printf("%-15s | %-30s%n", "Member ID", "Name");
System.out.println("----------------------------------------------");
}
public static void searchMember(Scanner input)
{
System.out.println("\n--- Search Member ---");
System.out.println("Search by (1) ID or (2) Name?");
System.out.print("Enter option (1 or 2): ");
int type = input.nextInt();
input.nextLine();
// --- Mock Logic ---
if (type == 1) {
System.out.print("Enter Member ID: ");
int id = input.nextInt();
input.nextLine();
System.out.println("\n[+] Found: ID " + id + ", Name: M. Khan");
} else if (type == 2) {
System.out.print("Enter Member Name: ");
String name = input.nextLine();
System.out.println("\n[+] Found: Name " + name + ", ID: 5001");
} else {
System.out.println("[!] Invalid search option.");
}
}
public static void viewIssuedBooksByMember(Scanner input)
{
System.out.println("\n--- View Issued Books by Member ---");
System.out.print("Enter Member ID: ");
int id = input.nextInt();
input.nextLine();
// --- Mock Logic ---
System.out.println("\n--- Books Issued to Member " + id + " ---");
System.out.printf("%-10s | %-30s | %-15s%n", "Book ID", "Title", "Issue Date");
System.out.println("---------------------------------------------------------------");
}
public static void removeMember(Scanner input)
{
System.out.println("\n--- Remove Member ---");
System.out.print("Enter Member ID to remove: ");
int id = input.nextInt();
input.nextLine();
// --- Mock Logic ---
if (id == 5002) {
System.out.println("\n[+] Member ID 5002 removed successfully.");
} else if (id == 5001) {
System.out.println("\n[!] Removal Failed: Member 5001 has outstanding books.");
} else {
System.out.println("\n[!] Member ID not found.");
}
}
public static void main(String args[])
{
Scanner input = new Scanner(System.in);
displayMainMenu();
System.out.println();
System.out.print("Enter your choice: ");
int choice = input.nextInt();
if (choice == 1)
{
int bookChoice;
bookMenu();
System.out.println();
System.out.print("Enter your choice: ");
bookChoice = input.nextInt();
switch (bookChoice) {
case 1:
addBook(input);
break;
case 2:
removeBook(input);
break;
case 3:
searchBook(input);
break;
case 4:
displayAvailableBooks();
break;
case 5:
issueBook(input);
break;
case 6:
returnBook(input);
break;
case 7:
updateBookDetails(input);
break;
case 8:
showAllIssuedBooks();
break;
case 9:
backToMainMenu();
break;
default:
System.out.println("[!] Invalid choice. Please try again.");
break;
}
}
if (choice == 2)
{
int roomChoice;
roomMenu();
System.out.println();
System.out.print("Enter choice: ");
roomChoice = input.nextInt();
switch (roomChoice) {
case 1:
showAvailableRooms();
break;
case 2:
reserveRoom();
break;
case 3:
cancelReservation();
break;
case 4:
checkReservationStatus(input);
break;
case 5:
System.out.println("-> Returning to Main Menu.");
break;
default:
System.out.println("[!] Invalid choice. Please try again.");
break;
}
}
if (choice == 3)
{
int memberChoice;
memberMenu();
System.out.println();
System.out.print("Enter choice: ");
memberChoice = input.nextInt();
switch (memberChoice) {
case 1:
registerNewMember(input);
break;
case 2:
displayAllMembers();
break;
case 3:
searchMember(input);
break;
case 4:
viewIssuedBooksByMember(input);
break;
case 5:
removeMember(input);
break;
case 6:
System.out.println("-> Returning to Main Menu.");
break;
default:
System.out.println("[!] Invalid choice. Please try again.");
break;
}
}
if (choice==4)
{
System.out.println("Thanks for using LMS");
System.exit(0);
}
if(choice < 1 || choice >4)
{
System.out.println("Invalid Choice, Please try again");
}
input.close();
}
}