-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLMS.java
More file actions
384 lines (334 loc) · 12.1 KB
/
LMS.java
File metadata and controls
384 lines (334 loc) · 12.1 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
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
class User {
private String userName;
private long contactNo;
private String mail;
private String address;
private String complaints;
private ArrayList<books> borrowedBooks = new ArrayList<>();
void menu(String n,Scanner input, Admin admin){
int userChoice=0;
do {
System.out.println("Hello "+n +" ! What would you like to do ");
System.out.println("1. See Books ");
System.out.println("2. Borrow Books ");
System.out.println("3. See borrowed books ");
System.out.println("4. Update profile ");
System.out.println("5. See My proile ");
System.out.println("6. Fill complain/suggestions ");
System.out.println("7. EXIT ");
System.out.print(">>> ");
userChoice= input.nextInt();
switch (userChoice) {
case 1:
admin.viewBook(input);
break;
case 2:
borrowBooks(input, admin);
break;
case 3:
showBorrowedBooks();
break;
case 4:
setDetails(input);
break;
case 5:
showUserDetails();
break;
case 6:
User temp=fillComplain(input);
admin.Complaints.add(temp);
break;
case 7:
System.out.println("Exiting....");
break;
default:
System.out.println("Please ENter a valid choice ");
break;
}
} while (userChoice!=7);
}
User fillComplain(Scanner input){
User temp = new User();
temp.userName = this.userName;
temp.mail = this.mail;
temp.contactNo = this.contactNo;
temp.address = this.address;
System.out.print("Please ENter your issue >> ");
temp.complaints = input.nextLine();
return temp;
}
void userComplaints(){
System.out.println("Name : " + this.userName);
System.out.println("E-mail " + this.mail);
System.out.println("Contact number : " + this.contactNo);
System.out.println("Issue : " + this.complaints);
System.out.println("\n-------------------------------------------------------------");
}
void setDetails(Scanner input) {
input.nextLine();
System.out.print("Enter Name : ");
this.userName = input.nextLine();
System.out.print("Enter mail : ");
this.mail = input.nextLine();
System.out.print("Enter address : ");
this.address = input.nextLine();
System.out.print("Enter contact number : ");
this.contactNo = input.nextLong();
}
void showUserDetails() {
System.out.println("Name : " + this.userName);
System.out.println("E-mail " + this.mail);
System.out.println("Contact number : " + this.contactNo);
System.out.println("Address : " + this.address);
}
void borrowBooks(Scanner input,Admin a){
input.nextLine();
System.out.print("Enter Name of the book : ");
String temp = input.nextLine();
System.out.print("Enter ISBN number of book : ");
int tempISBN= input.nextInt();
Iterator<books> it = a.Allbooks.iterator();
while (it.hasNext()){
books b = it.next();
if (b.getName().equalsIgnoreCase(temp) && b.getISBN() == tempISBN) {
if (b.getQuantity()>0) {
borrowedBooks.add(b);
b.setQuantity(b.getQuantity() -1 );
}else{
System.out.println("Sorry, The book is not avaialble right now");
}
}
}
}
void showBorrowedBooks() {
if (borrowedBooks.isEmpty()) {
System.out.println("No books borrowed");
return;
}else{
for (books b : borrowedBooks) {
b.show();
}
}
}
}
class books {
private String Name;
private float price;
private int ISBN;
private String author;
private int quantity;
void set(Scanner input) {
input.nextLine();
System.out.print("Enter Name of Book : ");
this.Name = input.nextLine();
System.out.print("Enter Author of Book : ");
this.author = input.nextLine();
System.out.print("Enter price of Book : ");
this.price = input.nextFloat();
System.out.print("Enter ISBN of Book : ");
this.ISBN = input.nextInt();
System.out.print("Enter Quantity of Book : ");
this.quantity = input.nextInt();
}
void show() {
System.out.println("Name : " + this.Name);
System.out.println("Author : " + this.author);
System.out.println("Price : " + this.price);
System.out.println("ISBN : " + this.ISBN);
System.out.println("Quantity : " + this.quantity);
System.out.println("---------------------------------------------------------------------");
}
String getName() {
return this.Name;
}
int getISBN(){
return this.ISBN;
}
int getQuantity(){
return this.quantity;
}
void setQuantity(int a){
if (a>=0)
this.quantity=a;
else
System.out.println("INVALID NUMBER ! ");
}
}
class Admin {
public ArrayList<User> Complaints = new ArrayList<>();
public ArrayList<books> Allbooks = new ArrayList<>();
public void menu(Scanner input) {
int Adminchoice = 0;
do {
System.out.println("----Welcome to Admin Panel----");
System.out.println("1. Add Book(s) ");
System.out.println("2. Remove Book(s) ");
System.out.println("3. View book(s) ");
System.out.println("4. See Due book(s) ");
System.out.println("4. View Complaints/Suggestion ");
System.out.println("5. Exit ");
System.out.print(">>> ");
while (!input.hasNextInt()) {
System.out.println("Please enter a valid choice ");
input.nextLine();
System.out.print(">>> ");
}
Adminchoice = input.nextInt();
switch (Adminchoice) {
case 1:
addBook(input);
break;
case 2:
removeBook(input);
break;
case 3:
viewBook(input);
break;
case 4:
dueBooks();
break;
case 5:
System.out.println("EXITING...");
break;
default:
break;
}
} while (Adminchoice != 5);
}
public boolean authenticate(Scanner input) {
System.out.print("Enter Your username : ");
String userName = input.nextLine();
System.out.print("Enter Your password : ");
String pass = input.nextLine();
String hashedEnteredPassword = Password.hashPassword(pass);
String hashedEntereduserName = Password.hashUsername(userName);
// Get the stored hashed password from the file
String storedPassword = Password.getStoredPassword();
// Get stpred username for admin
String storedUserName = Password.getStoredUserName();
if (storedPassword != null && storedUserName.equals(hashedEntereduserName)
&& storedPassword.equals(hashedEnteredPassword))
return true;
else
return false;
};
public void viewComplaints(){
Iterator<User> it = Complaints.iterator();
while (it.hasNext()) {
User u = it.next();
u.userComplaints();
}
}
public void addBook(Scanner input) {
books b = new books();
b.set(input);
Allbooks.add(b);
}
public void removeBook(Scanner input) {
String n;
input.nextLine();
System.out.print("ENter Name of the book : ");
n = input.nextLine();
Iterator<books> it = Allbooks.iterator();
boolean found = false;
while (it.hasNext()) {
books b = it.next();
if (b.getName().equalsIgnoreCase(n)) {
b.show();
it.remove();
found = true;
System.out.println("----BOOK DELETED SUCCESSFULLY----");
break;
}
}
if (found == false) {
System.out.println("----BOOK \" " + n + " \" Not Found----");
}
}
public void viewBook(Scanner input) {
String n;
input.nextLine();
System.out.println("ENter name of the book : ");
n = input.nextLine();
Iterator<books> it = Allbooks.iterator();
boolean found = false;
while (it.hasNext()) {
books b = it.next();
if (b.getName().equalsIgnoreCase(n)) {
b.show();
found = true;
}
}
if (found == false)
System.out.println("No book found with name \"" + n + "\" ");
}
public void dueBooks() {
}
}
public class LMS {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
Admin admin = new Admin();
User user = new User();
// if ( admin.authenticate(input)) {
// System.out.println("Access granted");
// }else
// System.out.println("Access not granted");
int Mchoice = 0;
do {
System.out.println("----------------WELCOME TO LIBRARY------------------------");
System.out.println("Select any choice :- ");
System.out.println("1. Admin ");
System.out.println("2. User ");
System.out.println("3. Exit ");
System.out.print(">>> ");
// To check for numeric inputs only
while (!input.hasNextInt()) {
System.out.println("Please enter a valid number ");
input.next();
System.out.print(">>>");
}
Mchoice = input.nextInt();
input.nextLine();
switch (Mchoice) {
case 1:
System.out.print("Do you want to set a new admin password? (yes/no): ");
String choice = input.nextLine().toLowerCase();
if (choice.equalsIgnoreCase("yes")) {
// For new userName
System.out.print("Enter new UserName : ");
String newUserName = input.nextLine();
String hashedUserName = Password.hashUsername(newUserName);
Password.saveUserName(hashedUserName);
System.out.println("UserName set successfully!");
// For setting new password
System.out.print("Enter new password: ");
String newPassword = input.nextLine();
String hashedPassword = Password.hashPassword(newPassword);
Password.savePassword(hashedPassword);
System.out.println(" Password set successfully!");
} else {
if (admin.authenticate(input))
admin.menu(input);
else
System.out.print("all not ok ");
}
break;
case 2:
break;
case 3:
break;
case 4:
System.out.print("EXITING");
break;
default:
System.out.println("Invalid choice.. Please Select from given options ");
break;
}
} while (Mchoice != 3);
input.close();
}
}