-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBookShop_Management_System.java
More file actions
364 lines (316 loc) · 8.24 KB
/
BookShop_Management_System.java
File metadata and controls
364 lines (316 loc) · 8.24 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
package BookStore;
import BookStore.Book;
import java.util.Scanner;
// Book Class
public class Book {
// member variable
private String Issbn;
private String BookName;
private String Author;
private String Edition;
private String publication;
Book() // Constructor function
{
Issbn =" ";
BookName = " ";
Author = " ";
Edition = " ";
publication = " ";
}
// setters
public void setIssbn(String Issbn) // set Isbn
{
this.Issbn = Issbn;
}
public void setBookName(String BookName) // to set book name
{
this.BookName = BookName;
}
public void setAuthor(String Author)
{
this.Author = Author;
}
public void setEdition(String Edition)
{
this.Edition = Edition;
}
public void setPublication(String publication)
{
this.publication = publication;
}
/// Getters
public String getIssbn()
{
return Issbn;
}
public String getBookName()
{
return BookName;
}
public String getAuthor()
{
return Author;
}
public String getEdition()
{
return Edition;
}
public String getPublication()
{
return publication;
}
// Methode.
// Add book method
public void add(String Issbn,String BookName, String Author, String Edition, String publication)
{
this.Issbn = Issbn;
this.BookName = BookName;
this.Author = Author;
this.Edition = Edition;
this.publication = publication;
}
/// To display data method
public void Display()
{
System.out.println("\nBook ISSBN no : "+ Issbn);
System.out.println("\nBook Name : "+ BookName);
System.out.println("\nBook author name : "+ Author);
System.out.println("\nBook edition : "+ Edition);
System.out.println("\nBook publication name : "+ publication);
}
}
// Main class
public class Main {
public static Scanner sc = new Scanner(System.in);
static int n =0; // total book no.
public static Book[] book = new Book[100];
public static void main(String[] args) {
Option(); // To see Menu & option
}
// Menu method
public static int Menu()
{
int choice;
do{
println("**********************************************");
println(" Welcome To Book Store Management System ");
println("**********************************************");
println("\n[1] Add Book");
println("[2] Update Book");
println("[3] Delete Book");
println("[4] Search Book");
println("[5] Show All Book");
println("[6] Quite");
print("\n\nEnter your choice : ");
choice = sc.nextInt();
if(choice <1 || choice > 6)
{
println("\n\tWrong.....Choice Again\n");
}
}
while(choice<0 || choice >6);
return choice;
}
// Option methode
public static void Option(){
int choice;
do{
choice = Menu();
switch(choice)
{
case 1:
addBook();
break;
case 2:
edit();
break;
case 3:
Delete();
break;
case 4:
Search();
break;
case 5 :
display();
break;
case 6:
println("\n++++++++++++++++++++++++++");
println("|\t\t End of operation |");
println("++++++++++++++++++++++++++");
break;
}
}
while(choice!=6);
}
// To add book in object's array
public static void addBook()
{
if(n>1000)
{
println("\t◇◇◇Book storage full◇◇◇");
}
else{
book[n] = new Book();
String issbn,name,author,ed,pub;
println("*****************************");
println("\n●●●📘 Add Book 📗●●●\n");
println("*****************************");
print("Enter book isbn no : ");
sc.nextLine();
issbn = sc.nextLine();
print("Enter book name : ");
name = sc.nextLine();
print("Enter Author name : ");
author = sc.nextLine();
print("Enter book edition : ");
ed = sc.nextLine();
print("Enter publication name : ");
pub = sc.nextLine();
book[n].add(issbn,name,author,ed,pub);
println("\n\n\t----------------------------");
println("\t■■■Successfully added■■■");
println("\t-----------------------------");
n++;
}
print("\nEnter any character to continue : ");
sc.next();
}
// To update/edit
public static void edit()
{
String Issbn;
print("Enter Book Issbn no : ");
sc.nextLine();
Issbn = sc.nextLine();
boolean isFound = false;
for(int i=0; i<n; i++)
{
String temp = book[i].getIssbn();
if(temp.equals(Issbn))
{
String name,author,ed,pub;
println("********************************");
println("●●●📘 Update Book 📗●●●");
println("********************************");
print("Enter book name : ");
name = sc.nextLine();
print("Enter Author name : ");
author = sc.nextLine();
print("Enter book edition : ");
ed = sc.nextLine();
print("Enter publication name : ");
pub = sc.nextLine();
book[i].add(temp,name,author,ed,pub);
println("\n\n\t----------------------------");
println("\t■■■Successfully added■■■");
println("\t-----------------------------");
isFound = true;
break;
}
}
if(!isFound)
{
println("---------------------");
println("| Book isn’t found |");
println("---------------------");
}
print("\nEnter any character to continue : ");
sc.next();
}
// to search book
public static void Search()
{
println("*****************************");
println(" 🔎🔎🔎 Search Book 📗🔍🔍🔍");
println("*****************************");
String ISBN;
print("Enrer Book ISBN no : ");
sc.nextLine();
ISBN = sc.nextLine();
boolean isFound = false;
for(int i=0; i<n; i++)
{
String temp = book[i].getIssbn();
if(temp.equals(ISBN))
{
isFound = true;
book[i].Display();
break;
}
}
if(!isFound)
{
println("---------------------");
println("| Book isn’t found |");
println("---------------------");
}
print("\nEnter any character to continue : ");
sc.next();
}
// to delete book from array
public static void Delete()
{
String Isbn;
print("Enter book isbn no : ");
sc.nextLine();
Isbn = sc.nextLine();
int pos = -1;
boolean isFound = false;
for(int i=0; i<n; i++)
{
String temp = book[i].getIssbn();
if(Isbn.equals(temp))
{
pos = i;
isFound = true;
break;
}
}
if(!isFound)
{
println("---------------------");
println("| Book isn’t found |");
println("---------------------");
}
else{
for(int i=pos; i<n-1; i++)
{
book[i].setIssbn(book[i+1].getIssbn());
book[i].setBookName(book[i+1].getBookName());
book[i].setAuthor(book[i+1].getAuthor());
book[i].setEdition(book[i+1].getEdition());
book[i].setPublication(book[i+1].getPublication());
}
n--;
println("\n\n----------------------------");
println("■■■Successfully Deleted ■■■");
println("-----------------------------");
}
}
// to display all data
public static void display()
{
if(n==0) {
println("There aren’t any Book. Please Add Book first ");
println("\nEnter any character to continue : ");
sc.next();
}
else {
for(int i=0; i<n; i++)
{
println("-----------------------");
println("| Book no : "+(i+1)+" |");
println("------------------------");
book[i].Display();
}
}
}
static void println(Object ob)
{
System.out.println(ob);
}
static void print(Object ob)
{
System.out.print(ob);
}
}