-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
112 lines (111 loc) · 4.34 KB
/
Main.java
File metadata and controls
112 lines (111 loc) · 4.34 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
import java.util.*;
public class Main {
public static void main(String[] args){
Library library=new Library();
Scanner sc=new Scanner(System.in);
while(true){
System.out.println("\n===== WELCOME =====");
System.out.println("1. login");
System.out.println("2. Register");
System.out.println("3. Exit");
int choice=sc.nextInt();
sc.nextLine();
if(choice==1){
System.out.println("User ID: ");
String uid=sc.nextLine();
System.out.println("Password: ");
String pass=sc.nextLine();
String role=library.login(uid,pass);
if(role==null){
System.out.println("Invalid login");
continue;
}
if(role.equalsIgnoreCase("admin")){
while(true){
System.out.println("\n===== ADMIN PANNEL =====");
System.out.println("1. Add book");
System.out.println("2. Issue book");
System.out.println("3. View books");
System.out.println("4. Logout");
int ch=sc.nextInt();
sc.nextLine();
switch(ch){
case 1:
System.out.println("Book ID: ");
String id=sc.nextLine();
System.out.println("Title: ");
String title=sc.nextLine();
System.out.println("Author: ");
String author=sc.nextLine();
library.addBook(new Book(id,title,author));
break;
case 2:
System.out.println("Book ID: ");
String bookid=sc.nextLine();
System.out.println("Enter User ID to issue book:");
String userid=sc.nextLine();
library.issueBook(bookid,userid);
break;
case 3:
library.showBooks();
break;
case 4:
System.out.println("Admin Logged out");
break;
}
if(ch==4) break;
}
}
else{
while(true){
System.out.println("\n===== LIBRARY SYSTEM =====");
System.out.println("1. View books");
System.out.println("2. Search Books");
System.out.println("3. Return book");
System.out.println("4. My transactions");
System.out.println("5. Logout");
int ch=sc.nextInt();
sc.nextLine();
switch(ch){
case 1:
library.showBooks();
break;
case 2:
System.out.println("Enter keyword to search: ");
library.searchBook(sc.nextLine());
break;
case 3:
System.out.println("Book ID: ");
library.returnBook(sc.nextLine());
break;
case 4:
library.showTransactions(uid);
break;
case 5:
System.out.println("User Logged out");
break;
}
if(ch==5) break;
}
}
}
else if(choice==2){
System.out.println("User ID: ");
String uid=sc.nextLine();
System.out.println("Name: ");
String name=sc.nextLine();
System.out.println("Password: ");
String pass=sc.nextLine();
System.out.println("Role (admin/User)");
String role=sc.nextLine();
library.registerUser(new User(uid,name,pass,role));
}else if(choice==3){
System.out.println("Exiting...");
break;
}else{
System.out.println("Invalid option");
}
}
sc.close();
}
}