-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
981 lines (861 loc) · 33.9 KB
/
Copy pathMain.java
File metadata and controls
981 lines (861 loc) · 33.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
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
import java.util.Scanner;
class Main {
private static final Scanner input = new Scanner(System.in);
// Credentials
static String username = "Isuru";
static String password = "456";
// 2D arrays for data storage
static String[][] suppliers = new String[100][2]; // [id, name]
static int supplierCount = 0;
static String[] categories = new String[100];
static int categoryCount = 0;
static String[][] items = new String[100][6]; // [code, supplierId, category, description, unitPrice, quantity]
static int itemCount = 0;
private final static void clearConsole() {
final String os = System.getProperty("os.name");
try {
if (os.equals("Linux")) {
System.out.print("\033\143");
} else if (os.equals("Windows")) {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
} else {
System.out.print("\033[H\033[2J");
System.out.flush();
}
} catch (final Exception e) {
System.err.println(e.getMessage());
}
}
public static void loginpage() {
clearConsole();
printTitle("LOGIN PAGE");
do {
System.out.print("\nUser name : ");
String uName = input.next();
if (uName.equals(username)) {
break;
} else {
System.out.println("user name is invalid.! Please try again.!");
}
} while (true);
do {
System.out.print("\nPassword : ");
String pass = input.next();
if (pass.equals(password)) {
break;
} else {
System.out.println("Password is incorrect..! Please try again.!");
}
} while (true);
}
public static void exitPage() {
clearConsole();
System.out.println("........................");
System.out.println("(Program exited with code: 0)");
System.out.println("Press return to continue...");
input.nextLine();
}
public static void homepage() {
do {
clearConsole();
printTitle("WELCOME TO THE PIGEON SERVICE STOCK MANAGEMENT SYSTEM");
System.out.print("\n");
System.out.printf("%-40s", "[1] Change the Credentials");
System.out.println("[2] Supplier Manage");
System.out.printf("%-40s", "[3] Stock Manage");
System.out.println("[4] Log Out");
System.out.printf("%-40s", "[5] Exit the System");
System.out.println("\n");
System.out.print("Enter a option to continue > ");
String num = input.next();
input.nextLine();
switch (num) {
case "1":
boolean relogin = credentialsManage();
if (relogin) {
loginpage();
}
break;
case "2":
supplierManage();
break;
case "3":
stockManage();
break;
case "4":
loginpage();
break;
case "5":
exitPage();
return;
default:
System.out.println("Invalid Input. Try Again!");
System.out.println("Press Enter to continue...");
input.nextLine();
}
} while (true);
}
public static boolean credentialsManage() {
clearConsole();
printTitle("CREDENTIAL MANAGE");
do {
System.out.print("\nEnter User name to verify it's you: ");
String uName = input.next();
if (uName.equals(username)) {
break;
} else {
System.out.println("user name is invalid.! Try again.!");
}
} while (true);
System.out.println("Hey " + username);
do {
System.out.print("\nEnter your Current Password : ");
String pass = input.next();
if (pass.equals(password)) {
break;
} else {
System.out.println("Password is incorrect..! Please try again.!");
}
} while (true);
System.out.print("Enter your New password : ");
input.nextLine();
String newPass = input.nextLine();
password = newPass;
System.out.println();
System.out.print("Password Change Sucessfully! ");
do {
System.out.print("Do you want to go home page (Y/N) : ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
return false;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return true;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
public static void supplierManage() {
while (true) {
clearConsole();
printTitle("SUPPLIER MANAGE");
System.out.println();
System.out.printf("%-40s", "[1] Add Supplier");
System.out.println("[2] Update Supplier");
System.out.printf("%-40s", "[3] Delete Supplier");
System.out.println("[4] View Suppliers");
System.out.printf("%-40s", "[5] Search Supplier");
System.out.println("[6] Home Page");
System.out.println();
System.out.print("Enter an option to continue > ");
String option = input.next();
input.nextLine();
switch (option) {
case "1":
addSupplier();
break;
case "2":
updateSupplier();
break;
case "3":
deleteSupplier();
break;
case "4":
viewSuppliers();
break;
case "5":
searchSupplier();
break;
case "6":
return;
default:
System.out.println("Invalid option! Please try again.");
System.out.println("Press Enter to continue...");
input.nextLine();
}
}
}
public static void addSupplier() {
while (true) {
clearConsole();
printTitle("ADD SUPPLIER");
String supplierId;
boolean exists;
do {
exists = false;
System.out.print("\nEnter Supplier ID: ");
supplierId = input.next();
for (int i = 0; i < supplierCount; i++) {
if (suppliers[i][0].equals(supplierId)) {
exists = true;
System.out.println("Supplier ID already exists! Please try different ID.");
break;
}
}
} while (exists);
input.nextLine();
System.out.print("Enter Supplier Name: ");
String supplierName = input.nextLine();
suppliers[supplierCount][0] = supplierId;
suppliers[supplierCount][1] = supplierName;
supplierCount++;
System.out.print("\nSupplier added successfully! ");
do {
System.out.print("Do you want to add another supplier (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
}
public static void updateSupplier() {
while (true) {
clearConsole();
printTitle("UPDATE SUPPLIER");
if (supplierCount == 0) {
System.out.println("\nNo suppliers found! Please add suppliers first.");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
int index = -1;
do {
System.out.print("\nSupplier ID : ");
String supplierId = input.next();
for (int i = 0; i < supplierCount; i++) {
if (suppliers[i][0].equals(supplierId)) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("Can't find supplier ID! Try again.");
} else {
break;
}
} while (true);
System.out.println("Current Supplier Name: " + suppliers[index][1]);
input.nextLine();
System.out.print("\nEnter New Supplier Name: ");
String newName = input.nextLine();
suppliers[index][1] = newName;
System.out.print("Supplier updated successfully! ");
do {
System.out.print("Do you want to update another supplier (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
}
public static void deleteSupplier() {
while (true) {
clearConsole();
printTitle("DELETE SUPPLIER");
System.out.println();
if (supplierCount == 0) {
System.out.println("No suppliers found! Please add suppliers first.");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
int index = -1;
String supplierId;
do {
System.out.print("\nEnter Supplier ID to delete: ");
supplierId = input.next();
for (int i = 0; i < supplierCount; i++) {
if (suppliers[i][0].equals(supplierId)) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("Can't find supplier ID. Try again.");
} else {
break;
}
} while (true);
for (int i = index; i < supplierCount - 1; i++) {
suppliers[i][0] = suppliers[i + 1][0];
suppliers[i][1] = suppliers[i + 1][1];
}
supplierCount--;
System.out.print("Supplier deleted successfully! ");
do {
System.out.print("Do you want to delete another supplier (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
}
public static void viewSuppliers() {
clearConsole();
printTitle("VIEW SUPPLIERS");
System.out.println();
System.out.println("+---------------+------------------------------+");
System.out.print("|");
System.out.printf("%-15s", "SUPPLIER ID");
System.out.print("|");
System.out.printf("%-30s", "SUPPLIER NAME");
System.out.println("|");
System.out.println("+---------------+------------------------------+");
for (int i = 0; i < supplierCount; i++) {
System.out.print("|");
System.out.printf("%-15s", suppliers[i][0]);
System.out.print("|");
System.out.printf("%-30s", suppliers[i][1]);
System.out.println("|");
}
System.out.println("+---------------+------------------------------+");
System.out.println();
do {
System.out.print("Do you want to go to supplier manage menu (Y/N): ");
String choice = input.next();
if (choice.equalsIgnoreCase("n")) {
System.exit(0);
} else if (choice.equalsIgnoreCase("y")) {
break;
} else {
System.out.println("invalid input");
}
} while (true);
}
public static void searchSupplier() {
while (true) {
clearConsole();
printTitle("SEARCH SUPPLIER");
if (supplierCount == 0) {
System.out.println("\nNo suppliers found! Please add suppliers first.");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
do {
System.out.print("\nEnter Supplier ID: ");
String supplierId = input.next();
boolean found = false;
for (int i = 0; i < supplierCount; i++) {
if (suppliers[i][0].equals(supplierId)) {
System.out.println("Supplier ID: " + suppliers[i][0]);
System.out.println("Supplier Name: " + suppliers[i][1]);
found = true;
break;
}
}
if (!found) {
System.out.println("Can't find supplier ID. Try again!");
} else {
break;
}
} while (true);
System.out.print("Supplier search successfully! ");
do {
System.out.print("Do you want to search another supplier (Y/N) ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
}
public static void stockManage() {
while (true) {
clearConsole();
printTitle("STOCK MANAGE");
System.out.println();
System.out.printf("%-40s", "[1] Manage Item Categories");
System.out.println("[2] Add Item");
System.out.printf("%-40s", "[3] Get Items Supplier Wise");
System.out.println("[4] View Items");
System.out.printf("%-40s", "[5] Rank Items Per Unit Price");
System.out.println("[6] Home Page");
System.out.println();
System.out.print("Enter an option to continue > ");
String option = input.next();
input.nextLine();
switch (option) {
case "1":
manageItemCategories();
break;
case "2":
addItem();
break;
case "3":
getItemsSupplierWise();
break;
case "4":
viewItems();
break;
case "5":
rankItemsPerUnitPrice();
break;
case "6":
return;
default:
System.out.println("Invalid option! Please try again.");
System.out.println("Press Enter to continue...");
input.nextLine();
}
}
}
public static void manageItemCategories() {
while (true) {
clearConsole();
printTitle("MANAGE ITEM CATEGORIES");
System.out.println();
System.out.printf("%-40s", "[1] Add New Item Category");
System.out.println("[2] Delete Item Category");
System.out.printf("%-40s", "[3] Update Item Category");
System.out.println("[4] Stock Management Menu");
System.out.println();
System.out.print("Enter an option to continue > ");
String option = input.next();
input.nextLine();
switch (option) {
case "1":
addItemCategory();
break;
case "2":
deleteItemCategory();
break;
case "3":
updateItemCategory();
break;
case "4":
return;
default:
System.out.println("Invalid option! Please try again.");
System.out.println("Press Enter to continue...");
input.nextLine();
}
}
}
public static void addItemCategory() {
do {
clearConsole();
printTitle("ADD ITEM CATEGORY");
System.out.println();
boolean exists;
String categoryName;
do {
exists = false;
System.out.print("Enter the new item Category : ");
categoryName = input.next();
for (int i = 0; i < categoryCount; i++) {
if (categories[i].equalsIgnoreCase(categoryName)) {
System.out.println("Category already exists! Please try different Category.");
exists = true;
break;
}
}
} while (exists);
categories[categoryCount] = categoryName;
categoryCount++;
System.out.print("Added successfully!");
do {
System.out.print(" Do you want to add another Category (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
} while (true);
}
public static void deleteItemCategory() {
do {
clearConsole();
printTitle("DELETE ITEM CATEGORY");
if (categoryCount == 0) {
System.out.println("\nNo categories found!");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
int index = -1;
String categoryName;
do {
System.out.print("\nEnter Category Name to delete: ");
categoryName = input.next();
for (int i = 0; i < categoryCount; i++) {
if (categories[i].equalsIgnoreCase(categoryName)) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("Category not found!");
} else {
break;
}
} while (true);
for (int i = index; i < categoryCount - 1; i++) {
categories[i] = categories[i + 1];
}
categoryCount--;
System.out.print("Category deleted successfully!");
do {
System.out.print(" Do you want to delete another category (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
} while (true);
}
public static void updateItemCategory() {
do {
clearConsole();
printTitle("UPDATE ITEM CATEGORY");
if (categoryCount == 0) {
System.out.println("\nNo categories found!");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
int index = -1;
do {
System.out.print("\nEnter Current Category Name: ");
String currentName = input.nextLine();
for (int i = 0; i < categoryCount; i++) {
if (categories[i].equalsIgnoreCase(currentName)) {
index = i;
break;
}
}
if (index == -1) {
System.out.println("Category not found! try again.");
} else {
break;
}
} while (true);
System.out.print("Enter New Category Name: ");
String newName = input.nextLine();
categories[index] = newName;
System.out.print("Category updated successfully! ");
do {
System.out.print("Do you want to update another Category (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
} while (true);
}
public static void addItem() {
do {
clearConsole();
printTitle("ADD ITEM");
System.out.println();
if (categoryCount == 0) {
System.out.println("Oops! It seems you don't have any item categories in the system.");
System.out.print("Do you want to add a new item category (Y/N): ");
String choice = input.nextLine();
if (choice.equalsIgnoreCase("Y")) {
addItemCategory();
return;
} else {
return;
}
}
if (supplierCount == 0) {
System.out.println("Oops! No suppliers found!");
System.out.print("Do you want to add a new supplier (Y/N): ");
String choice = input.nextLine();
if (choice.equalsIgnoreCase("Y")) {
addSupplier();
return;
} else {
return;
}
}
boolean exists;
String itemCode;
do {
exists = false;
System.out.print("Enter Item Code: ");
itemCode = input.next();
for (int i = 0; i < itemCount; i++) {
if (items[i][0].equals(itemCode)) {
System.out.println("Item code already exists! Try another.");
exists = true;
}
}
} while (exists);
System.out.println();
System.out.println("Supplier List:");
System.out.println("+-----+---------------+------------------------------+");
System.out.printf("|%-5s|%-15s|%-30s|", "NO", "SUPPLIER ID", "SUPPLIER NAME");
System.out.println();
System.out.println("+-----+---------------+------------------------------+");
for (int i = 0; i < supplierCount; i++) {
System.out.printf("|%-5d|%-15s|%-30s|", (i + 1), suppliers[i][0], suppliers[i][1]);
System.out.println();
}
System.out.println("+-----+---------------+------------------------------+");
int supplierNo;
do {
System.out.print("\nEnter Supplier Number > ");
supplierNo = input.nextInt();
if (supplierNo <= 0 || supplierNo > supplierCount) {
System.out.println("Invalid supplier number! Enter valid number.");
} else {
break;
}
} while (true);
System.out.println();
System.out.println("Item Category List:");
System.out.println("+-----+------------------------------+");
System.out.printf("|%-5s|%-30s|", "NO", "CATEGORY NAME");
System.out.println();
System.out.println("+-----+------------------------------+");
for (int i = 0; i < categoryCount; i++) {
System.out.printf("|%-5d|%-30s|", (i + 1), categories[i]);
System.out.println();
}
System.out.println("+-----+------------------------------+");
int categoryNo;
do {
System.out.print("\nEnter Category Number> ");
categoryNo = input.nextInt();
if (categoryNo <= 0 || categoryNo > categoryCount) {
System.out.println("Invalid category number! Enter valid number.");
} else {
break;
}
} while (true);
input.nextLine();
System.out.print("\nDescription: ");
String description = input.nextLine();
System.out.print("Unit Price: ");
double unitPrice = input.nextDouble();
System.out.print("Quantity on Hand: ");
int quantity = input.nextInt();
items[itemCount][0] = itemCode;
items[itemCount][1] = suppliers[supplierNo - 1][0];
items[itemCount][2] = categories[categoryNo - 1];
items[itemCount][3] = description;
items[itemCount][4] = String.valueOf(unitPrice);
items[itemCount][5] = String.valueOf(quantity);
itemCount++;
System.out.print("Item added successfully! ");
do {
System.out.print("Do you want to add another item (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
break;
} else if (yesOrNo.equalsIgnoreCase("n")) {
return;
} else {
System.out.println("\nInvalid input ");
}
} while (true);
} while (true);
}
public static void getItemsSupplierWise() {
clearConsole();
printTitle("ITEMS SUPPLIER WISE");
System.out.println();
if (supplierCount == 0) {
System.out.println("No supplier found! Enter suppliers first.");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
boolean supplierExists;
String supplierId;
do {
supplierExists = false;
System.out.print("Enter Supplier ID: ");
supplierId = input.next();
for (int i = 0; i < supplierCount; i++) {
if (suppliers[i][0].equals(supplierId)) {
System.out.println("Supplier Name : " + suppliers[i][1]);
supplierExists = true;
break;
}
}
if (!supplierExists) {
System.out.println("Supplier not found!");
}
} while (!supplierExists);
System.out.println();
System.out.println("+------------+--------------------+------------+----------+---------------+");
System.out.printf("|%-12s|%-20s|%-12s|%-10s|%-15s|\n",
"ITEM CODE", "DESCRIPTION", "UNIT PRICE", "QTY", "CATEGORY");
System.out.println("+------------+--------------------+------------+----------+---------------+");
boolean found = false; // This is the declaration that was missing
for (int i = 0; i < itemCount; i++) {
if (items[i][1].equals(supplierId)) {
System.out.printf("|%-12s|%-20s|%-12s|%-10s|%-15s|\n",
items[i][0], items[i][3], items[i][4],
items[i][5], items[i][2]);
found = true;
}
}
System.out.println("+------------+--------------------+------------+----------+---------------+");
if (!found) {
System.out.println("No items found for this supplier!");
}
do {
System.out.print(" Do you want to go supplier manage page (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
return;
} else if (yesOrNo.equalsIgnoreCase("n")) {
System.exit(0);
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
public static void viewItems() {
clearConsole();
printTitle("VIEW ITEMS");
System.out.println();
if (itemCount == 0) {
System.out.println("No items found!");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
for (int c = 0; c < categoryCount; c++) {
String currentCategory = categories[c];
boolean hasItems = false;
for (int i = 0; i < itemCount; i++) {
if (items[i][2].equalsIgnoreCase(currentCategory)) {
hasItems = true;
break;
}
}
if (hasItems) {
System.out.println();
System.out.println("Category: " + currentCategory.toUpperCase());
System.out.println("+------------+---------------+--------------------+------------+----------+");
System.out.printf("|%-12s|%-15s|%-20s|%-12s|%-10s|\n",
"ITEM CODE", "SUPPLIER ID", "DESCRIPTION", "UNIT PRICE", "QTY");
System.out.println("+------------+---------------+--------------------+------------+----------+");
for (int i = 0; i < itemCount; i++) {
if (items[i][2].equalsIgnoreCase(currentCategory)) {
System.out.printf("|%-12s|%-15s|%-20s|%-12s|%-10s|\n",
items[i][0], items[i][1], items[i][3],
items[i][4], items[i][5]);
}
}
System.out.println("+------------+---------------+--------------------+------------+----------+");
}
}
do {
System.out.print("Do you want to go stock manage page (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
return;
} else if (yesOrNo.equalsIgnoreCase("n")) {
System.exit(0);
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
public static void rankItemsPerUnitPrice() {
clearConsole();
printTitle("RANK ITEMS PER UNIT PRICE");
System.out.println();
if (itemCount == 0) {
System.out.println("No items found!");
System.out.println("Press Enter to continue...");
input.nextLine();
return;
}
// Create a copy of items array for sorting
String[][] sortedItems = new String[itemCount][];
for (int i = 0; i < itemCount; i++) {
sortedItems[i] = items[i].clone();
}
// Bubble sort by unit price (ascending order)
for (int i = 0; i < itemCount - 1; i++) {
for (int j = 0; j < itemCount - 1 - i; j++) {
double price1 = Double.parseDouble(sortedItems[j][4]);
double price2 = Double.parseDouble(sortedItems[j + 1][4]);
if (price1 > price2) {
// Swap items
String[] temp = sortedItems[j];
sortedItems[j] = sortedItems[j + 1];
sortedItems[j + 1] = temp;
}
}
}
System.out
.println("+---------------+------------+--------------------+------------+----------+---------------+");
System.out.printf("|%-15s|%-12s|%-20s|%-12s|%-10s|%-15s|\n",
"SUPPLIER ID", "ITEM CODE", "DESCRIPTION", "UNIT PRICE", "QTY", "CATEGORY");
System.out
.println("+---------------+------------+--------------------+------------+----------+---------------+");
for (int i = 0; i < itemCount; i++) {
System.out.printf("|%-15s|%-12s|%-20s|%-12s|%-10s|%-15s|\n",
sortedItems[i][1], sortedItems[i][0], sortedItems[i][3],
sortedItems[i][4], sortedItems[i][5], sortedItems[i][2]);
}
System.out
.println("+---------------+------------+--------------------+------------+----------+---------------+");
do {
System.out.print("Do you want to go stock manage page (Y/N): ");
String yesOrNo = input.next();
if (yesOrNo.equalsIgnoreCase("y")) {
return;
} else if (yesOrNo.equalsIgnoreCase("n")) {
System.exit(0);
} else {
System.out.println("\nInvalid input ");
}
} while (true);
}
public static void printTitle(String title) {
String line = "--------------------------------------------------------------------------------------------------";
System.out.println("+" + line + "+");
int before = (line.length() - title.length()) / 2;
System.out.printf("|%" + before + "s", "");
System.out.print(title);
int after = (line.length() - title.length()) - before;
System.out.printf("%" + after + "s", "");
System.out.println("|");
System.out.println("+" + line + "+");
}
public static void main(String[] args) {
loginpage();
homepage();
input.close();
}
}