-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
480 lines (332 loc) · 17.9 KB
/
Main.java
File metadata and controls
480 lines (332 loc) · 17.9 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
package src.oopJava;
/*
Author: Spyros Tsioupros
Year: 2021
1st year university project
*/
import java.util.Scanner;
//main class
public class Main {
//static attributes
static int k = 0; //variable legth of array vivlia (k <= 10)
static boolean isSortISBN = false; //logic variable to check if array is sorted respect to isbn or publish year
static boolean isSortEtEkd = false;
//constant
static final int N = 10;//capacity of array
//------------------------------------Main method
public static void main(String[] args){
//--------------variables
int selec;//user's selection
int epilEpeks;
int bookCategory;
//------------initialize vivlia array
Book[] vivlia = new Book[N];
/*
*
random initialize
*
vivlia[0] = new Science("Engineer", "Microelectronics", "Konstantinos Hatzopoulos", "9781572580145", "Tziola", 1001, 2002, 110.5);
vivlia[1] = new Science("Physics", "Quantum Mechanics 2", "Tai Hunduminda", "9780385737951", "Hindi-English Publishers", 910, 2008, 90.2);
vivlia[2] = new Dictionary(10000, "English-Greek Language", "Matthew McChristopher", "9783453401372", "Iakinthos", 1000, 2007, 70.9);
vivlia[3] = new Dictionary(1000, "Spanish-Greek Dictionary", "Sandy Cazorlia", "9780155658110", "Santa Publizer", 100, 1992, 20);
vivlia[4] = new Science("Mathematics", "Linear Algebra & Complex Numbers", "Panagiotis Henry", "9781292061429", "Pythagoras", 820, 2000, 75.5);
*
*
*
*
*
*/
do{
mainMenu();//main menu display
selec = new Scanner(System.in).nextInt();//user's selection
switch(selec){//main switch
//##################################case 1
case 1: {
++k;//increment the variable length of book array
if(k <= N ){//if k is out of capacity go to else
//enter title
System.out.println("\n\nEnter title: ");
String titl = new Scanner(System.in).nextLine();
//enter author name
System.out.println("\nEnter author full name: ");
String fullName = new Scanner(System.in).nextLine();
//enter publish year
System.out.println("\nEnter year of publish: ");
int publYear = new Scanner(System.in).nextInt();
//enter isbn
System.out.println("\nEnter ISBN: ");
String isbn = new Scanner(System.in).nextLine();
//enter publisher
System.out.println("\nEnter publisher: ");
String publisher = new Scanner(System.in).nextLine();
//enter page number
System.out.println("\nEnter number of pages: ");
int pages = new Scanner(System.in).nextInt();
//enter price
System.out.println("\nEnter price: ");
double timi = new Scanner(System.in).nextDouble();
//enter book category
do{//user's selection for defin the book category 1.Science, 2.Dictionary
System.out.println("\nEnter book category: ");
System.out.println("1-->Science\n2-->Dictionary");
bookCategory = new Scanner(System.in).nextInt();
}while(bookCategory > 3);
if(bookCategory == 1){
System.out.println("\nEnter science field: ");
String sci = new Scanner(System.in).nextLine();
vivlia[k-1] = new Science(sci, titl, fullName, isbn, publisher, pages, publYear, timi);//downcast Book --> Science
}
else{
System.out.println("\nEnter number of translated words: ");
int dict = new Scanner(System.in).nextInt();
vivlia[k-1] = new Dictionary(dict, titl, fullName, isbn, publisher, pages, pages, timi);//downcast Book --> Dictionary
}
break;//end of "for"
}//end of if
else{
System.out.println("\nThere is no space for more books");
}
} break;//end of case 1
//##################################case 2
case 2:{
if(k == 0){ //if there are 0 books on vivlia[] you can't enter to case 2
System.out.println(" The libary is empty...");
break;
}
do{//if the user's selection is over 4 then go back to main menu
eplEpeksergasias();//selection2 menu
epilEpeks = new Scanner(System.in).nextInt();//user's selection
switch(epilEpeks){
case 1:{ //search of book in vivlia[]
searchBook(vivlia);
} break;//back to main menu
case 2:{ //sort of books in vivlia[]
sortArray(vivlia);
} break;//back to main menu
case 3:{ //print books between two prices (from.....to)
metaksiTimwn(vivlia);
} break;//back to main menu
case 4:{ //display all books of vivlia[]
displayFullInformations(vivlia);
} break;//back to main menu
}
}while(epilEpeks < 5);
}break;//end of case 2
//##################################case 3
case 3:{
if(k == 0){ //if there are 0 books on vivlia[] you can't enter to case 3
System.out.println(" The libary is empty...");
break;
}
int epilPwl;
do{
menuSelThree();// display menu
epilPwl = new Scanner(System.in).nextInt();//user's selection
switch(epilPwl){
case 1:{
//enter books for sale
eisagwgiVivlPwlish(vivlia);
}break;
case 2:{
//calculate incomes from sale of every book category (dictionary, science) and the sum of these
DaySales.incomeFromSales(vivlia);
}break;
case 3:{
//the arrays vivlia[], antitypaSales[] and pSales[] matche same indexes to the same data
System.out.println("\nThe dialy Best-Seller is: " + vivlia[DaySales.dailyBestSeller()].getTitle());
}break;
case 4:{
//display info about sales if books
DaySales.displaySales(vivlia);
}break;
}
}while(epilPwl < 5);
}break;//end of case 3
}//end of main switch
}while(selec < 4);//end of program with selec >= 5
}
//-----------------------------------secondary methods
//method for algorithm to choose the right searching algorith (linear or binary) if array is sorting or not
public static void searchBook(Book[] vivlia){
int epilogiAnaz;
do{
secMenu();
epilogiAnaz = new Scanner(System.in).nextInt();
if(epilogiAnaz == 1){
System.out.println("Enter book's isbn that you looking for: ");//enter of searching book's isbn
String givenIsbn = new Scanner(System.in).nextLine();
if(isSortISBN == false){ //if array isn't sort respect to ISBN...
if(MyUtils.seqSearch(vivlia, givenIsbn) != -1)//if found
System.out.println("The book found!");
else
System.out.println("Unfortunatly, book not found");
return;
}
//else if(isSortISBN == true)
if(MyUtils.binSearch(vivlia, givenIsbn) != -1)//if found
System.out.println("The book found!");
else
System.out.println("Unfortunatly, book not found");
}//end if(epilAnaz == 1)
else if(epilogiAnaz == 2){
System.out.println("Dose etos ekdosis tou vivliou pou anazitas: ");//enter of searching book's publish year
int givenEtKik = new Scanner(System.in).nextInt();
if(isSortEtEkd == false){//if array is sort respect to ISBN...
if(MyUtils.seqSearch(vivlia, givenEtKik) != -1)//if found
System.out.println("The book found!");
else
System.out.println("Unfortunatly, book not found");
return;
}
//else if(isSortEtEkd == true)
if(MyUtils.binSearch(vivlia, givenEtKik) != -1)//if found
System.out.println("The book found!");
else
System.out.println("Unfortunatly, book not found");
} //end if(epilAnaz == 2)
}while(epilogiAnaz < 3);
return;//end
}
//method that call method-algorithm for sorting
public static void sortArray(Book[] vivlia){
if(k == 0)
System.out.println("The libary is empty...");
else{
int epilTaks;//user select for sorting field (Full name, isbn, publish year, price)
int epilMethod;//user select for sorting method-algorithm
do{
epilTaks();//display menu
epilTaks = new Scanner(System.in).nextInt();//user's input
if(epilTaks == 1){//--------------block for sorting respect to author's name
epilMethod();//display the menu of sorting algorithms
epilMethod = new Scanner(System.in).nextInt();//user's input for sorting method-algorithms
if(epilMethod == 1){ MyUtils.bubbleSortFullName(vivlia);}
else if(epilMethod == 2){ MyUtils.insertSortFullName(vivlia);}
else if(epilMethod == 3){ MyUtils.selectSortFullName(vivlia);}
else if(epilMethod == 4){ MyUtils.quickSortFullName(vivlia);}
else if(epilMethod == 5){ MyUtils.mergeSortFullName(vivlia);}
}
else if(epilTaks == 2){//--------------block for sorting respect to ISBN
epilMethod();//display the menu of sorting algorithms
epilMethod = new Scanner(System.in).nextInt();//user's input for sorting method-algorithms
if(epilMethod == 1){MyUtils.bubbleSortISBN(vivlia);}
else if(epilMethod == 2){MyUtils.insertSortISBN(vivlia);}
else if(epilMethod == 3){MyUtils.selectSortISBN(vivlia);}
else if(epilMethod == 4){MyUtils.quickSortISBN(vivlia);}
else if(epilMethod == 5){MyUtils.mergeSortISBN(vivlia);}
}
else if(epilTaks == 3){//--------------block for sorting respect to publish year
epilMethod();//display the menu of sorting algorithms
epilMethod = new Scanner(System.in).nextInt();//user's input for sorting method-algorithms
if(epilMethod == 1){ MyUtils.bubbleSortEtEkd(vivlia);}
else if(epilMethod == 2){ MyUtils.insertSortEtEkd(vivlia);}
else if(epilMethod == 3){ MyUtils.selectSortEtEkd(vivlia);}
else if(epilMethod == 4){ MyUtils.quickSortEtEkd(vivlia);}
else if(epilMethod == 5){ MyUtils.mergeSortEtEkd(vivlia);}
}
else if(epilTaks == 4){//--------------block for sorting respect to price
epilMethod();//display the menu of sorting algorithms
epilMethod = new Scanner(System.in).nextInt();//user's input for sorting method-algorithms
if(epilMethod == 1){ MyUtils.bubbleSortPrice(vivlia);}
else if(epilMethod == 2){ MyUtils.insertSortPrice(vivlia);}
else if(epilMethod == 3){ MyUtils.selectSortPrice(vivlia);}
else if(epilMethod == 4){ MyUtils.quickSortPrice(vivlia);}
else if(epilMethod == 5){ MyUtils.mergeSortPrice(vivlia);}
}
}while(epilTaks < 5);//---------------exit from sorting field
}
return;
}
//method for user's 2 inputs (1st input "from"....2nd input "to") prices
public static void metaksiTimwn(Book[] vivlia){
//attributes
double from;
double to;
//user enters the 2 prices
System.out.println("Enter a price area from: ");
from = new Scanner(System.in).nextDouble();
System.out.println("To: ");
to = new Scanner(System.in).nextDouble();
MyUtils.valueSearch(from, to, vivlia);
}
//method to display all informations about vivlia's objects
public static void displayFullInformations(Book[] vivlia){
for(int i = 0; i < k; i++){
System.out.println("\n~Book: #"+ (i+1)+"----------------");
System.out.println("~Title: "+vivlia[i].getTitle());
System.out.println("~Full name: "+vivlia[i].getFullName());
System.out.println("~ISBN: "+vivlia[i].getISBN());
System.out.println("~Publisher: "+vivlia[i].getPublisher());
System.out.println("~Pages: "+vivlia[i].getPages());
System.out.println("~Publish year: "+vivlia[i].getPublYear());
System.out.println("~Price: "+vivlia[i].getPrice());
}
}
//method that user enter isbn of book for sale
public static void eisagwgiVivlPwlish(Book[] vivlia){
//attributes
String isbn;
System.out.println("Enter isbn of book that is sold: ");
isbn = new Scanner(System.in).nextLine();//user's input
DaySales.copyBookSalesPlus(isbn, vivlia);
}
//-----------------------------------display menu methods
//method to display case 3 menu
public static void menuSelThree(){
System.out.println("\n Choices to manage sales");
System.out.println("1. Register new sale");
System.out.println("2. Sow income from sales");
System.out.println("3. Daily best-seller");
System.out.println("4. Show informations of all sales");
System.out.println("5. Go back to the main list of choices");
System.out.println("Give a choice (1-5)");
}
//method to display main menu
public static void mainMenu(){
System.out.println("\n\nSelection list");
System.out.println("1. Enter a Book");
System.out.println("2. Procces the registered books");
System.out.println("3. Sale a book");
System.out.println("4. Finish the program");
System.out.println("Give a choice (1-4):");
}
//method to display case 2 method
public static void secMenu(){
System.out.println("\n\n Select searching method: ");
System.out.println("1. ISBN ");
System.out.println("2. Publish year");
System.out.println("3. Go back to the main list of choices");
System.out.println("Give a choice (1-3): ");
}
//method for sorting, searching etc the vivlia's data (case 2)
public static void eplEpeksergasias(){
System.out.println("\n Select procces: ");
System.out.println("1. Search book");
System.out.println("2. Sort books");
System.out.println("3. Show books between two prices");
System.out.println("4. Show up all informations of all books");
System.out.println("5. Go back to the main menu");
System.out.println("Give a choice (1-5)");
}
//method to select object's sorting
public static void epilTaks(){
System.out.println("\n Select sort method: ");
System.out.println("1. Author name");
System.out.println("2. ISBN");
System.out.println("3. Publish year");
System.out.println("4. Price");
System.out.println("5. Go back to the main list of choices");
System.out.println("Give a choice (1-5)");
}
//method to select sorting algorithm
public static void epilMethod(){
System.out.println("\n Select sort algorithm: ");
System.out.println("1. Bubble sort");
System.out.println("2. Insertion sort");
System.out.println("3. Selection sort");
System.out.println("4. Quick sort");
System.out.println("5. Merge sort");
System.out.println("6. Go back to the list of sorting choices");
System.out.println("Give a choice (1-6)");
}
}