-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLibrarian.java
183 lines (176 loc) · 6.76 KB
/
Librarian.java
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
import java.io.IOException;
import java.util.Scanner;
public class Librarian {
public static void mainPage() throws IOException {
System.out.printf("----------Welcome to the main page of librarian----------"
+ "%n 1. Add a new member"
+ "%n 2. Add/Modify/Delete books"
+ "%n 3. Manage books"
+ "%n 4. clock in/out"
+ "%n 5. go back"
+ "%n Answer: ");
Scanner s = new Scanner(System.in);
int input = s.nextInt();
switch (input) {
case 1:
AddMember();
break;
case 2:
AddModifyDelete();
break;
case 3:
ManageBooks();
break;
case 4:
ClockinOut();
break;
case 5:
Library.login();
break;
default:
System.out.println("Wrong choice enter again");
mainPage();
break;
}
}
public static void AddMember() throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("Enter member username: ");
String a = s.next();
System.out.println("Enter Password: ");
String b = s.next();
if (Database.addUser(a, b) == true) {
System.out.println("Member created");
Logger.addlog("A new Member (" + a + ") Created");
} else {
System.out.println("There was a problem");
}
System.out.println("1. Library Page \n2. Librarian Page");
int input = s.nextInt();
switch (input) {
case 1:
Library.login();
break;
case 2:
mainPage();
break;
}
}
public static void AddModifyDelete() throws IOException {
Scanner s = new Scanner(System.in);
Scanner s1 = new Scanner(System.in);
Scanner s2 = new Scanner(System.in);
Scanner s3 = new Scanner(System.in);
System.out.println("1. Add a new book"
+ "\n2. Modify a book"
+ "\n3. Delete a book"
+ "\n Answer: ");
int input1 = s.nextInt();
switch (input1) {
case 1:
System.out.printf("Enter book Name: ");
String a1 = s1.nextLine();
System.out.println("Enter Author's name: ");
String b1 = s2.nextLine();
System.out.println("Enter Category: ");
String c2 = s3.nextLine();
if (Database.addBook(a1, b1,c2,true) == true) {
System.out.println("Book added");
Logger.addlog("A new Book (" + a1 + ") has been created");
} else {
System.out.println("There was a problem");
}
mainPage();
break;
case 2:
System.out.printf("Enter book Name: ");
a1 = s1.nextLine();
System.out.println("Enter Author's name: ");
b1 = s2.nextLine();
System.out.println("Enter Category: ");
c2 = s3.nextLine();
System.out.printf("Enter new book Name: ");
String a2 = s1.nextLine();
System.out.println("Enter new Author's name: ");
String b2 = s2.nextLine();
System.out.println("Enter new Category: ");
String c3 = s3.nextLine();
System.out.println("--Modify was Successfull--");
Database.edit(a2, b2, c3, true, a1, b1, c2, true);
Logger.addlog("Book "+a1+" was edited");
mainPage();
break;
case 3:
System.out.println("Enter the name of the book that you want to delete:"
+ "\n Answer: ");
String a = s1.nextLine();
Database.delete(a);
System.out.println("Book Deleted Successfully");
Logger.addlog("Book "+a+" was deleted");
mainPage();
break;
default:
System.out.println("Wrong choice enter again");
mainPage();
break;
}
mainPage();
}
public static void ManageBooks() throws IOException {
Scanner s = new Scanner(System.in);
Scanner s1 = new Scanner(System.in);
Scanner s2 = new Scanner(System.in);
System.out.println("1. borrow a book"
+ "\n2. return a book");
int input3 = s.nextInt();
switch (input3) {
case 1:
System.out.println("Enter the name of the book you want to borrow:"
+ "\n");
String a = s1.nextLine();
if(Database.borrow(a)==true){
Logger.addlog("Book "+a+" was borrowed");
System.out.println("--Book Borrowed Successfully--");
}else{
System.out.println("Book not found or already borrowed");
}
mainPage();
break;
case 2:
System.out.println("Enter the name of the book you want to return:"
+ "\n");
String b = s2.nextLine();
if(Database.return1(b)==true){
Logger.addlog("Book "+b+" was returned");
System.out.println("--Book returned Successfully--");
}else{
System.out.println("Book name not found or not borrowed");
}
mainPage();
break;
}
}
public static void ClockinOut() throws IOException {
Scanner s = new Scanner(System.in);
System.out.println("1. clock in \n2. clock out");
int input4 = s.nextInt();
switch (input4) {
case 1:
System.out.println("What time is it?");
String time = s.next();
Database.clockin(time);
System.out.println("Time in recorded");
Logger.addlog("Librarian Clocked in at "+time);
mainPage();
break;
case 2:
System.out.println("What time is it?");
time = s.next();
Database.clockout(time);
System.out.println("Time out Saved");
Logger.addlog("Librarian Clocked out at "+time);
mainPage();
break;
}
}
}