-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibraryManagementSystem.java
More file actions
264 lines (150 loc) · 5.3 KB
/
Copy pathLibraryManagementSystem.java
File metadata and controls
264 lines (150 loc) · 5.3 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
/*import javax.swing.*;
import java.awt.Graphics;
public class java_programs extends JPanel {
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawString("Hello, World!", 150, 150);
}
public static void main(String[] args) {
JFrame frame = new JFrame("First Applet");
frame.add(new java_programs());
frame.setSize(400, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}*/
import java.util.Scanner;
public class LibraryManagementSystem {
static Scanner sc = new Scanner(System.in);
static String books[] = new String[100];
static boolean issued[] = new boolean[100];
static String issuedTo[] = new String[100];
static int totalBooks = 0;
public static void main(String[] args) {
int choice;
while (true) {
System.out.println("\n==============================");
System.out.println(" LIBRARY MANAGEMENT SYSTEM");
System.out.println("==============================");
System.out.println("1. Add Book");
System.out.println("2. Display Books");
System.out.println("3. Search Book");
System.out.println("4. Issue Book");
System.out.println("5. Return Book");
System.out.println("6. Exit");
System.out.print("\nEnter your choice : ");
choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
addBook();
break;
case 2:
displayBooks();
break;
case 3:
searchBook();
break;
case 4:
issueBook();
break;
case 5:
returnBook();
break;
case 6:
System.out.println("\nThank You...");
System.exit(0);
default:
System.out.println("Invalid Choice");
}
}
}
static void addBook() {
System.out.print("\nEnter Book Name : ");
books[totalBooks] = sc.nextLine();
issued[totalBooks] = false;
issuedTo[totalBooks] = "";
totalBooks++;
System.out.println("Book Added Successfully.");
}
static void displayBooks() {
if (totalBooks == 0) {
System.out.println("\nNo Books Available.");
return;
}
System.out.println("\n-------- BOOK LIST --------");
for (int i = 0; i < totalBooks; i++) {
System.out.print((i + 1) + ". " + books[i]);
if (issued[i])
System.out.println(" --> Issued to " + issuedTo[i]);
else
System.out.println(" --> Available");
}
}
static void searchBook() {
if (totalBooks == 0) {
System.out.println("\nNo Books Available.");
return;
}
System.out.print("\nEnter Book Name to Search : ");
String search = sc.nextLine();
boolean found = false;
for (int i = 0; i < totalBooks; i++) {
if (books[i].equalsIgnoreCase(search)) {
found = true;
System.out.println("\nBook Found");
System.out.println("Book Name : " + books[i]);
if (issued[i])
System.out.println("Status : Issued to " + issuedTo[i]);
else
System.out.println("Status : Available");
break;
}
}
if (!found)
System.out.println("Book Not Found.");
}
static void issueBook() {
if (totalBooks == 0) {
System.out.println("\nNo Books Available.");
return;
}
System.out.print("\nEnter Book Name to Issue : ");
String name = sc.nextLine();
for (int i = 0; i < totalBooks; i++) {
if (books[i].equalsIgnoreCase(name)) {
if (issued[i]) {
System.out.println("Book is Already Issued.");
return;
}
System.out.print("Enter Student Name : ");
issuedTo[i] = sc.nextLine();
issued[i] = true;
System.out.println("Book Issued Successfully.");
return;
}
}
System.out.println("Book Not Found.");
}
static void returnBook() {
if (totalBooks == 0) {
System.out.println("\nNo Books Available.");
return;
}
System.out.print("\nEnter Book Name to Return : ");
String name = sc.nextLine();
for (int i = 0; i < totalBooks; i++) {
if (books[i].equalsIgnoreCase(name)) {
if (!issued[i]) {
System.out.println("This Book is Already Available.");
return;
}
issued[i] = false;
issuedTo[i] = "";
System.out.println("Book Returned Successfully.");
return;
}
}
System.out.println("Book Not Found.");
}
}