-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStockManagement.java
More file actions
1273 lines (1052 loc) · 46.3 KB
/
StockManagement.java
File metadata and controls
1273 lines (1052 loc) · 46.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
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
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.util.Scanner;
class UnAndPw {
private String userName = "admin";
private String parssword = "admin";
public UnAndPw() {
}
public UnAndPw(String userName, String parssword) {
this.userName = userName;
this.parssword = parssword;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getUserName() {
return userName;
}
public void setParssword(String parssword) {
this.parssword = parssword;
}
public String getParssword() {
return parssword;
}
}
class Suppliers {
private String id;
private String name;
public Suppliers() {
}
public Suppliers(String id, String name) {
this.id = id;
this.name = name;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
class Categories {
private String name;
public Categories() {
}
public Categories(String name) {
this.name = name;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
class Items {
private String sid;
private String code;
private String desc;
private String price;
private String qty;
private String cate;
public Items() {
}
public Items(String sid, String code, String desc, String price, String qty, String cate) {
this.sid = sid;
this.code = code;
this.desc = desc;
this.price = price;
this.qty = qty;
this.cate = cate;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getSid() {
return sid;
}
public void setCode(String code) {
this.code = code;
}
public String getCode() {
return code;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getDesc() {
return desc;
}
public void setPrice(String price) {
this.price = price;
}
public String getPrice() {
return price;
}
public void setQty(String qty) {
this.qty = qty;
}
public String getQty() {
return qty;
}
public void setCate(String cate) {
this.cate = cate;
}
public String getCate() {
return cate;
}
}
class StockManagement {
private static Scanner s = new Scanner(System.in);
private static UnAndPw u1 = new UnAndPw();
private static Suppliers[] sList = new Suppliers[0];
private static Categories[] cList = new Categories[0];
private static Items[][] iList = new Items[0][0];
public static void main(String[] args) {
logIn();
}
public static void logIn() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\t LOGIN PAGE\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
while (true) {
System.out.print("Enter your username: ");
String un = s.next();
if (un.equals(u1.getUserName())) {
while (true) {
System.out.print("\nEnter your password: ");
String pw = s.next();
if (pw.equals(u1.getParssword())) {
homePage();
return;
} else {
System.out.println("Password is incorrect. Please try again!");
}
}
} else {
System.out.println("User name is invalid. Please try again!\n");
}
}
}
public static void homePage() {
clearConsole();
System.out.print("+------------------------------------------------------------------------------+\n|\t\t WELCOME TO PIGEON STOCK MANAGEMENT SYSTEM\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
System.out.println("[1] Change the credentials\t\t[2] Supplier manage\n[3] Stock manage\t\t\t[4] Log out\n[5] Exit the system\n");
L1:
while (true) {
System.out.print("Enter an option to continue > ");
String option = s.next();
switch (option) {
case "1":
clearConsole();
changeTheCredentials();
break L1;
case "2":
clearConsole();
supplierManage();
break L1;
case "3":
clearConsole();
stockManage();
break L1;
case "4":
clearConsole();
logIn();
break L1;
case "5":
clearConsole();
System.out.println("━━━━━━━━━━━━━━━\n Thank you\n━━━━━━━━━━━━━━━");
return;
default:
System.out.println("Not an option! try again.\n");
}
}
}
public static void changeTheCredentials() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tCREDENTIAL MANAGE\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while (true) {
System.out.print("Please enter the user name to verify it's you: ");
String un = s.next();
if (un.equals(u1.getUserName())) {
System.out.println("\nHey " + u1.getUserName());
while (true) {
System.out.print("\nEnter your current password: ");
String pw = s.next();
if (pw.equals(u1.getParssword())) {
System.out.print("\nEnter your new password: ");
String newPs = s.next();
u1.setParssword(newPs);
System.out.print("\nPassword changed successfully! Do you want to go home page (Y/N) : ");
String check = s.next();
while (true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
homePage();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
logIn();
break L1;
} else {
System.out.print("\nInvalid option! try again. Do you want to go home page (Y/N) ? ");
check = s.next();
}
}
} else {
System.out.println("Incorrect password. try again!");
}
}
} else {
System.out.println("Invalid user name. try again!\n");
}
}
}
public static void supplierManage() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tSUPPLIER MANAGE\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
System.out.println("[1] Add supplier\t\t[2] Update supplier\n[3] Delete supplier\t\t[4] View suppliers\n[5] Search supplier\t\t[6] Home page\n");
L1:
while (true) {
System.out.print("Enter an option to continue > ");
String option = s.next();
switch (option) {
case "1":
clearConsole();
addSupplier();
break L1;
case "2":
clearConsole();
updateSupplier();
break L1;
case "3":
clearConsole();
deleteSupplier();
break L1;
case "4":
clearConsole();
viewSuppliers();
break L1;
case "5":
clearConsole();
searchSupplier();
break L1;
case "6":
clearConsole();
homePage();
break L1;
default:
System.out.println("Not an option! try again.\n");
}
}
}
public static void addSupplier() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\t ADD SUPPLIER\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
sList = growArrayS();
L1:
while(true) {
System.out.print("\nSupplier ID\t: ");
String id = s.next();
if(checkDuplicateId(id)) { //Verify that this ID has not been used previously
System.out.println("Already exists! try another supplier id.");
continue;
}else{
System.out.print("Supplier Name\t: ");
String name = s.next();
Suppliers temp = new Suppliers();
temp.setId(id);
temp.setName(name);
sList[sList.length - 1] = temp;
}
System.out.print("\nAdded successfully! Do you want to add another supplier (Y/N) ? ");
String check = s.next();
while(true){
if (check .equals("Y") || check .equals("y")) {
clearConsole();
addSupplier();
break L1;
} else if (check .equals("N") || check .equals("n")) {
clearConsole();
supplierManage();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to add another supplier (Y/N) ? ");
check = s.next();
}
}
}
}
public static void updateSupplier() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\t UPDATE SUPPLIER\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while(true) {
System.out.print("Supplier ID\t: ");
String ID = s.next();
int supplierIndex = -1;
supplierIndex = findSupplier(ID); //Find the index of specific suppliers in an array
if (supplierIndex != -1) {
System.out.println("Supplier Name\t: " + sList[supplierIndex].getName());
System.out.print("\nEnter the new supplier name : ");
String name = s.next();
sList[supplierIndex].setName(name);
System.out.print("\nUpdate Successfully! Do you want to update another supplier (Y/N) ? ");
String check = s.next();
while(true){
if (check .equals("Y") || check .equals("y")) {
clearConsole();
updateSupplier();
break L1;
} else if (check .equals("N") || check .equals("n")) {
clearConsole();
supplierManage();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to update another supplier (Y/N) ? ");
check = s.next();
}
}
} else {
System.out.println("Can't find supplier id. try again!\n");
}
}
}
public static void deleteSupplier() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\t DELETE SUPPLIER\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while(true) {
System.out.print("Supplier ID\t: ");
String id = s.next();
int supplierIndex = -1;
supplierIndex = findSupplier(id); //Find the index of specific suppliers in an array
if(supplierIndex != -1) {
sList = shrinkArray(supplierIndex); //Delete specific suppliers from an array
deleteCopySupplierItem(id); //Delete items that supplier provide
System.out.print("\nDelete successfully! Do you want to delete another supplier (Y/N) ? ");
String check = s.next();
while(true) {
if (check .equals("Y") || check .equals("y")) {
clearConsole();
deleteSupplier();
break L1;
} else if (check .equals("N") || check .equals("n")) {
clearConsole();
supplierManage();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to delete another supplier (Y/N) ? ");
check = s.next();
}
}
}else{
System.out.println("Can't find supplier id. try again!\n");
}
}
}
public static void viewSuppliers() {
System.out.print("+-------------------------------------------------------------------------------+\n|\t\t\t\t VIEW SUPPLIERS\t\t\t\t\t|\n+-------------------------------------------------------------------------------+\n\n");
if(sList.length > 0) {
System.out.printf("%s\n%c%16S%5c%17S%4c\n%s\n", "+--------------------+--------------------+", '|', "SUPPLIER ID", '|', "SUPPLIER NAME", '|', "+--------------------+--------------------+");
for (int i = 0; i < sList.length; i++) {
System.out.printf("%-8c%-13s%-8c%-13s%c\n", '|', sList[i].getId(), '|', sList[i].getName(), '|');
}
System.out.println("+--------------------+--------------------+");
System.out.print("\nDo you want to go supplier manage page (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
supplierManage();
break;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
homePage();
break;
} else {
System.out.print("\nInvalid option! try again. Do you want to go supplier manage page (Y/N) ? ");
check = s.next();
}
}
}else{
System.out.print("Can't find any suppliers! Do you want to add suppliers (Y/N) ? ");
String check = s.next();
while(true){
if(check .equals("Y") || check .equals("y")){
clearConsole();
addSupplier();
break;
}else if(check .equals("N") || check .equals("n")){
clearConsole();
supplierManage();
break;
}else{
System.out.print("\nInvalid option! try again. Do you want to add suppliers (Y/N) ? ");
check = s.next();
}
}
}
}
public static void searchSupplier() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\t SEARCH SUPPLIER\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while(true) {
System.out.print("Supplier ID\t: ");
String id = s.next();
int supplierIndex = -1;
supplierIndex = findSupplier(id); //Find the index of specific suppliers in an array
if (supplierIndex != -1) {
System.out.println("Supplier Name\t: " + sList[supplierIndex].getName());
System.out.print("\nDo you want to find another supplier (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
searchSupplier();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
supplierManage();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to find another supplier (Y/N) ? ");
check = s.next();
}
}
} else {
System.out.println("Can't find supplier id! try again.\n");
}
}
}
public static void stockManage() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tSTOCK MANAGEMENT\t\t\t |\n+------------------------------------------------------------------------------+\n\n");
System.out.println("[1] Manage item categories\t\t[2] Add item\n[3] Get item supplier wise\t\t[4] View items\n[5] Rank item per unit Price\t\t[6] Home page\n");
L1:
while(true){
System.out.print("Enter an option to continue > ");
String option = s.next();
switch (option) {
case "1":
clearConsole();
manageItemCategories();
break L1;
case "2":
clearConsole();
addItem();
break L1;
case "3":
clearConsole();
getItemSupplierWise();
break L1;
case "4":
clearConsole();
viewItems();
break L1;
case "5":
clearConsole();
rankItemPerUnitPrice();
break L1;
case "6":
clearConsole();
homePage();
break L1;
default :
System.out.println("Not an option! try again.\n");
}
}
}
public static void manageItemCategories() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t MANAGE ITEM CATEGORY\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
System.out.println("[1] Add new item category\t\t[2] Delete item category\n[3] Update item category\t\t[4] Stock management\n");
L1:
while (true) {
System.out.print("Enter an option to continue > ");
String option = s.next();
switch (option) {
case "1":
clearConsole();
addNewItemCategory();
break L1;
case "2":
clearConsole();
deleteItemCategory();
break L1;
case "3":
clearConsole();
updateItemCategory();
break L1;
case "4":
clearConsole();
stockManage();
break L1;
default :
System.out.println("Not an option! try again.\n");
}
}
}
public static void addNewItemCategory() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tADD ITEM CATEGORY\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
cList = growArrayC(); //Grow category array to save category type
iList = growArrayCategory(); //Grow items array to add items to that category
L1:
while(true) {
System.out.print("Enter the new item category : ");
String type = s.next();
int index = -1;
index = checkCategory(type); //Make sure category name doesn't duplicate
if (index != -1) {
System.out.println("Category already exist!\n");
}else {
Categories temp = new Categories();
temp.setName(type);
cList[cList.length - 1] = temp;
System.out.print("\nAdded successfully! Do you want to add another category (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
addNewItemCategory();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
manageItemCategories();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to add another category (Y/N) ? ");
check = s.next();
}
}
}
}
}
public static void updateItemCategory(){
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t UPDATE ITEM CATEGORY\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while(true) {
System.out.print("Enter current category name : ");
String type = s.next();
int index = -1;
index = checkCategory(type); //Find the index of the category
if(index != -1){
System.out.print("\nEnter new category name : ");
String name = s.next();
cList[index].setName(name);
System.out.print("\nUpdate Successfully! Do you want to update another category (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
updateItemCategory();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
manageItemCategories();
break L1;
}else {
System.out.print("\nInvalid option! try again. Do you want to update another category (Y/N) ? ");
check = s.next();
}
}
}else{
System.out.println("Can't find category! try again.\n");
}
}
}
public static void deleteItemCategory() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t DELETE ITEM CATEGORY\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
L1:
while(true) {
System.out.print("Enter category type : ");
String type = s.next();
int index = -1;
index = checkCategory(type); //Find the index of the category
if(index != -1){
cList = removeCategory(index); //Remove category from category array
iList = removeItemCategory(index); //Remove items that belong to the category
System.out.print("\nDelete Successfully! Do you want to delete another category (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
deleteItemCategory();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
manageItemCategories();
break L1;
} else {
System.out.print("\nInvalid option! try again. Do you want to delete another category (Y/N) ? ");
check = s.next();
}
}
}else{
System.out.println("Can't find category! try again.\n");
}
}
}
public static void addItem() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tADD ITEM\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
if(cList.length == 0) { //Make sure system have categories
System.out.print("Oops! It seems that you don't have any item categories in the system.\nDo you want to add a new item category (Y/N) ? ");
String check = s.next();
while(true){
if(check .equals("Y") || check .equals("y")) {
clearConsole();
addNewItemCategory();
break;
}else if(check .equals("N") || check .equals("n")) {
clearConsole();
stockManage();
break;
}else{
System.out.print("\nInvalid option! try again. Do you want to add a new item category (Y/N) ? ");
check = s.next();
}
}
}else if(sList.length == 0) { //Make sure system have suppliers
System.out.print("Oops! It seems that you don't have any suppliers in the system.\nDo you want to add a new supplier (Y/N) ? ");
String check = s.next();
while(true){
if(check .equals("Y") || check .equals("y")){
clearConsole();
addSupplier();
break;
}else if(check .equals("N") || check .equals("n")){
clearConsole();
stockManage();
break;
}else{
System.out.print("\nInvalid option! try again. Do you want to add a new supplier (Y/N) ? ");
check = s.next();
}
}
}else{
L1:
while(true) {
System.out.print("Item code\t: ");
String code = s.next();
if (checkDuplicateItem(code)) { //Make sure item code doesn't duplicate
System.out.println("Item code already exist! try again.\n");
}else{
int sIndex = -1;
int cIndex = -1;
printSuppliers();
while(true){
System.out.print("Enter the supplier number > ");
String sNumber = s.next();
if(isNumber(sNumber)){
sIndex = Integer.parseInt(sNumber);
if(sIndex > 0 && (sIndex - 1) < sList.length){ //Make sure supplier number is valid
break;
}else {
System.out.println("Enter number from table!\n");
}
}else {
System.out.println("Enter valid number!\n");
}
}
printCategory();
while(true){
System.out.print("Enter the category number > ");
String cNumber = s.next();
if(isNumber(cNumber)){
cIndex = Integer.parseInt(cNumber);
if(cIndex > 0 && (cIndex - 1) < cList.length){ //Make sure category number is valid
break;
}else {
System.out.println("Enter number from table!\n");
}
}else {
System.out.println("Enter valid number!\n");
}
}
System.out.print("\nDescription :");
String description = s.next();
System.out.print("\nUnit price : ");
String price = s.next();
System.out.print("\nQty on hand : ");
String qty = s.next();
int index = cIndex - 1;
growArrayItem(index); //Grow array belong to specific category to add item data
Items temp = new Items();
temp.setSid(sList[sIndex - 1].getId());
temp.setCode(code);
temp.setDesc(description);
temp.setPrice(price);
temp.setQty(qty);
iList[index][iList[index].length - 1] = temp;
System.out.print("\nAdded successfully! Do you want to add another item (Y/N) ? ");
String check = s.next();
while(true){
if(check .equals("Y") || check .equals("y")){
clearConsole();
addItem();
break L1;
}else if(check .equals("N") || check .equals("n")){
clearConsole();
stockManage();
break L1;
}else{
System.out.print("\nInvalid option! try again. Do you want to add another item (Y/N) ? ");
check = s.next();
}
}
}
}
}
}
public static void getItemSupplierWise() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tSEARCH SUPPLIER\t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
if (sList.length != 0) { //Check whether the system has suppliers
L1:
while (true) {
System.out.print("Enter supplier id\t: ");
String id = s.next();
int index = -1;
index = findSupplier(id); //Verify the existence of specific suppliers
if (index != -1) {
System.out.println("\nSupplier name\t\t: " + sList[index].getName() + "\n\n");
System.out.printf("%s\n%-6c%-15s%-6c%-15s%-6c%-15s%-6c%-15s%-7c%-14s%c\n%s\n", "+--------------------+--------------------+--------------------+--------------------+--------------------+", '|', "ITEM CODE", '|', "DESCRIPTION", '|', "UNIT PRICE", '|', "QTY ON HAND", '|', "CATEGORY", '|', "+--------------------+--------------------+--------------------+--------------------+--------------------+");
for (int i = 0; i < iList.length; i++) {
for (int j = 0; j < iList[i].length; j++) {
if (iList[i][j] != null && iList[i][j].getSid() != null && iList[i][j].getSid() .equals(id)) {
System.out.printf("%-7c%-14s%-6c%-15s%-7c%-14s%-7c%-14s%-7c%-14s%c\n", '|', iList[i][j].getCode(), '|', iList[i][j].getDesc(), '|', iList[i][j].getPrice(), '|', iList[i][j].getQty(), '|', cList[i].getName(), '|');
}
}
}
System.out.println("+--------------------+--------------------+--------------------+--------------------+--------------------+\n");
System.out.print("Search successfully! Do you want to search another supplier (Y/N) ? ");
String check = s.next();
while (true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
getItemSupplierWise();
break L1;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
stockManage();
break L1;
} else {
System.out.print("\nInvalid option! try again. Do you want to search another supplier (Y/N) ? ");
check = s.next();
}
}
} else {
System.out.println("Can't find supplier! try again.\n");
}
}
} else {
System.out.print("It's look like you don't have any suppliers!\nDo you like to add suppliers (Y/N) ? ");
String check = s.next();
while (true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
addSupplier();
break;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
stockManage();
break;
}else{
System.out.print("\nInvalid option! try again. Do you like to add suppliers (Y/N) ? ");
check = s.next();
}
}
}
}
public static void viewItems() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tVIEW ITEMS \t\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
if(cList.length != 0) { //Ensure that categories are added in the system
for (int i = 0; i < cList.length; i++) {
if (iList[i] != null) { //Ensure that items are added in the categories
System.out.printf("%s%c\n%s\n%-9c%-12s%-9c%-12s%-9c%-12s%-8c%-13s%-9c%-12s%c\n%s\n", cList[i].getName(), ':', "+--------------------+--------------------+--------------------+--------------------+--------------------+", '|', "SID", '|', "CODE", '|', "DESC", '|', "PRICE", '|', "QTY", '|', "+--------------------+--------------------+--------------------+--------------------+--------------------+");
for (int j = 0; j < iList[i].length; j++) {
System.out.printf("%-8c%-13s%-8c%-13s%-7c%-14s%-8c%-13s%-8c%-13s%c\n", '|', iList[i][j].getSid(), '|', iList[i][j].getCode(), '|', iList[i][j].getDesc(), '|', iList[i][j].getPrice(), '|', iList[i][j].getQty(), '|');
}
System.out.println("+--------------------+--------------------+--------------------+--------------------+--------------------+\n");
}else{
System.out.println(cList[i] + " category doesn't have any items.\n");
}
}
System.out.print("Do you want to go to stock manage page (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
stockManage();
break;
} else if (check.equals("N") || check.equals("n")) {
clearConsole();
homePage();
break;
} else {
System.out.print("Invalid option! try again. Do you want to go to stock manage page (Y/N) ? ");
check = s.next();
}
}
}else{
System.out.print("There isn't any category in this system! Do you want to add categories (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {
clearConsole();
addNewItemCategory();
break;
}else if(check.equals("N") || check.equals("n")){
clearConsole();
stockManage();
break;
}else{
System.out.print("Invalid option! try again. Do you want to add categories (Y/N) ? ");
check = s.next();
}
}
}
}
public static void rankItemPerUnitPrice() {
System.out.print("+------------------------------------------------------------------------------+\n|\t\t\t\tRANKED UNIT PRICE\t\t\t\t|\n+------------------------------------------------------------------------------+\n\n");
Items[] sortArr = copyArray(); //Copy all the items from 3D array to 2D array
sortArr = sortArray(sortArr); //Sort 2D array
if(sortArr.length != 0) {
System.out.printf("%s\n%-9c%-12S%-9c%-12S%-9c%-12S%-9c%-12S%-10c%-12S%-9c%-12S%c\n%s\n", "+--------------------+--------------------+--------------------+--------------------+---------------------+--------------------+", '|', "SID", '|', "CODE", '|', "DESC", '|', "PRICE", '|', "QTY", '|', "CAT", '|', "+--------------------+--------------------+--------------------+--------------------+---------------------+--------------------+");
for (int i = 0; i < sortArr.length; i++) {
System.out.printf("%-7c%-14S%-7c%-14S%-7c%-14S%-7c%-14S%-7c%-15S%-7c%-14S%c\n", '|', sortArr[i].getSid(), '|', sortArr[i].getCode(), '|', sortArr[i].getDesc(), '|', sortArr[i].getPrice(), '|', sortArr[i].getQty(), '|', sortArr[i].getCate(), '|');
}
System.out.println("+--------------------+--------------------+--------------------+--------------------+---------------------+--------------------+\n");
System.out.print("Do you want to go to stock manage page (Y/N) ? ");
String check = s.next();
while(true) {
if (check.equals("Y") || check.equals("y")) {