-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRiskMatrix.java
824 lines (739 loc) · 35.4 KB
/
RiskMatrix.java
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
package Git.MiniProject;
import java.util.ArrayList;
public class RiskMatrix {
// Background
public static final String ANSI_GREEN_BACKGROUND = "\u001B[42m"; //"\033[42m" Green
public static final String ANSI_YELLOW_BACKGROUND = "\u001B[43m"; // Yellow
public static final String ANSI_RED_BACKGROUND = "\u001B[41m"; // Red
public static final String CYAN_BRIGHT = "\033[0;96m"; // CYAN
public static final String WHITE_UNDERLINED = "\033[4;37m"; // WHITE
// Bold
public static final String BLACK_BOLD = "\033[1;30m"; // BLACK
// Reset
public static final String RESET = "\033[0m"; // Text Reset
public static final int REGISTER_RISK = 1;
public static final int PRINT_RISKS = 2;
public static final int EDIT_RISKS = 3;
public static final int CONVERT_PROBABILITY_AND_IMPACT_TO_PERCENTAGE = 4;
public static final int QUIT = 5;
public static final int INITIAL = 0;
public static final int FIRST = 1;
public static final int IMPACT_SCALE = 25;
public static final int PROBABILITY_SCALE = 120;
public static final double IMPACT_LIMIT = 10.0;
private Project currentProject;
public RiskMatrix(Project currentProject){
this.currentProject = currentProject;
}
public Project getCurrentProject() {
return currentProject;
}
public void printMenu (){
System.out.println("SELECT FROM THE FOLLOWING OPTIONS");
System.out.println();
System.out.println(" 1. REGISTER RISK.");
System.out.println(" 2. PRINT RISK.");
System.out.println(" 3. EDIT RISK.");
System.out.println(" 4. CONVERT PROBABILITY AND IMPACT TO PERCENTAGE VALUES.");
System.out.println(" 5. QUIT.");
System.out.println();
}
public void runRisk(){ // this methods handles all the risk matrix functions.
int option;
int loopCounter = 0;
do {
loopCounter++;
if (loopCounter == FIRST){
System.out.println();
System.out.println("========= RISK MATRIX =========");
System.out.println();
}
printMenu();
System.out.print("Enter an option from the above: ");
option = new KeyboardInput().positiveInt();
switch (option){
case REGISTER_RISK:
registerRisk();
System.out.println("**************************************");
break;
case PRINT_RISKS:
printFunction();
System.out.println("**************************************");
break;
case EDIT_RISKS:
editRisk();
System.out.println("**************************************");
case CONVERT_PROBABILITY_AND_IMPACT_TO_PERCENTAGE:
percentageConverter();
System.out.println("**************************************");
break;
case QUIT:
System.out.println("**************************************");
break;
default:
System.out.println("Enter the right value");
break;
}
} while (option != QUIT);
}
public void registerRisk ( ){ // this method handles risk registration
if(currentProject != null){
String riskID = readRiskID();
String riskName = readRiskName();
String riskType = readRiskType();
System.out.print("Risk Probability (b/n 0.0 and 1.0) : ");
double probability = new KeyboardInput().positiveDouble();
probability = new RiskEvaluator().probability(probability);
System.out.print("Risk Impact (b/n 0.0 and 10.0):");
double impact = new KeyboardInput().positiveDouble();
impact = new RiskEvaluator().impact(impact);
currentProject.getRisks().add(new Risk(riskID, riskName, riskType, probability, impact));
}
}
public void printFunction (){
int option;
final int PRINT_RISK_MATRIX = 1;
final int PRINT_A_SPECIFIC_RISK = 2;
final int PRINT_ALL_REGISTERED_RISKS = 3;
final int PRINT_NUMBER_OF_REGISTERED_RISKS = 4;
final int QUIT_PRINT_FUNCTION = 5;
if(currentProject != null){
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
do {
System.out.println("SELECT FROM THE FOLLOWING OPTIONS.");
System.out.println();
System.out.println(" 1. PRINT GRAPHICAL RISK MATRIX ");
System.out.println(" 2. PRINT A SPECIFIC RISK ");
System.out.println(" 3. PRINT ALL REGISTERED RISKS ");
System.out.println(" 4. DISPLAY NUMBER OF REGISTERED RISKS ");
System.out.println(" 5. QUIT PRINT FUNCTION ");
System.out.println();
option = new KeyboardInput().positiveInt();
switch (option){
case PRINT_RISK_MATRIX:
printRiskMatrix();
System.out.println("*************************************************************************");
break;
case PRINT_A_SPECIFIC_RISK:
printSpecificRisk();
System.out.println("**************************************************************************************************");
break;
case PRINT_ALL_REGISTERED_RISKS:
printAllRisks();
System.out.println("**************************************************************************************************");
break;
case PRINT_NUMBER_OF_REGISTERED_RISKS:
printNumberOfRisk();
System.out.println("*******************************");
break;
case QUIT_PRINT_FUNCTION:
System.out.println("Exiting.....");
break;
default:
System.out.println("Enter a correct option.");
break;
}
new ProjectManagementTool().pause();
} while (option!=QUIT_PRINT_FUNCTION);
} else {
System.out.println("There is no registered risk.");
}
} else {
System.out.println("There is no registered project.");
}
}
public void editRisk (){
final int NAME = 1;
final int PROBABILITY = 2;
final int IMPACT = 3;
final int TYPE = 4;
final int STATUS = 5;
final int REMOVE = 6;
final int QUIT_EDIT = 7;
int option;
if(currentProject != null){
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
do {
System.out.println("What would you like to edit?");
System.out.println();
System.out.println(" 1. Edit Risk Name.");
System.out.println(" 2. Edit Risk Probability.");
System.out.println(" 3. Edit Risk Impact.");
System.out.println(" 4. Edit Risk Type.");
System.out.println(" 5. Update Risk Status.");
System.out.println(" 6. Remove Risk.");
System.out.println(" 7. Quit Editing");
option = new KeyboardInput().positiveInt();
switch (option){
case NAME:
boolean repeat;
do{
repeat = false;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if (foundRisk != null) {
System.out.print("Enter new name: ");
String newName = new KeyboardInput().Line();
newName = new RiskEvaluator().name(newName);
foundRisk.setRiskName(newName);
System.out.println("You have successfully updated the risk's name to " + foundRisk.getRiskName());
} else {
System.out.println("The risk name your are trying to access is not registered");
repeat = true;
}
} while (repeat);
break;
case PROBABILITY://
do{
repeat = false;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if (foundRisk != null ){
System.out.print("Enter the new probability value: ");
double newProbability = new KeyboardInput().positiveDouble();
newProbability = new RiskEvaluator().probability(newProbability);
foundRisk.setProbability(newProbability);
System.out.println("You have successfully updated the risk's probability to " + foundRisk.getProbability());
} else {
System.out.println("The risk name you are trying to access is not registered.");
repeat = true;
}
} while (repeat);
break;
case IMPACT:
do{
repeat = false;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if(foundRisk != null){
System.out.print("Enter the new impact value : ");
double newImpact = new KeyboardInput().positiveDouble();
newImpact = new RiskEvaluator().impact(newImpact);
foundRisk.setImpact(newImpact);
System.out.println("You have successfully updated the risk's impact to " + foundRisk.getImpact());
} else {
System.out.println("The risk name you are trying to access is not registered.");
repeat = true;
}
} while (repeat);
break;
case TYPE:
{
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if(foundRisk != null){
System.out.println("Do you want to change the current type of risk : (" + foundRisk.getRiskType() + ") ?");
System.out.print("Enter Y or N ");
String choice = new KeyboardInput().Line();
choice = new DataEvaluator().yesOrNo(choice);
if(choice.equals("Y")){
if(foundRisk.getRiskType().equals("Predicted")){
foundRisk.setRiskType(" New "); //intentional spaces
} else {
foundRisk.setRiskType("Predicted");
}
System.out.println("Risk type successfully changed to: " + foundRisk.getRiskType());
} else {
System.out.println("Editing the type has been left unchanged");
}
}
}
break;
case STATUS:
{
final int TBM = 1;
final int MANAGED = 2;
final int COMMUNICATE = 3;
final int EFFORT = 4;
final int GONE = 5;
final int QUIT = 6;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if (foundRisk != null){
int choice;
do{
System.out.println(" Options of Risk Status update: ");
System.out.println(" 1. To be Managed,");
System.out.println(" 2. Managed,");
System.out.println(" 3. Communicated,");
System.out.println(" 4. Effort Made,");
System.out.println(" 5. Disappeared,");
System.out.println(" 6. Quit Updating.");
System.out.println("Choose option of Status ");
choice = new KeyboardInput().positiveInt();
} while (choice > QUIT);
switch (choice){
case TBM:
foundRisk.setRiskStatus("To Be Managed");
break;
case MANAGED:
foundRisk.setRiskStatus("Managed");
break;
case COMMUNICATE:
foundRisk.setRiskStatus("Communicated");
break;
case EFFORT:
foundRisk.setRiskStatus("Effort Made");
break;
case GONE:
foundRisk.setRiskStatus("Disappeared");
break;
default: //if not all the above
System.out.println("Exiting....");
}
if(choice < QUIT){
System.out.println("Status successfully updated to : " + foundRisk.getRiskStatus());
}
}
}
break;
case REMOVE:
do{
repeat = false;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if ( foundRisk != null){
System.out.println("Are you sure you want to delete " + foundRisk.getRiskName() + "?" );
deleteRisk(foundRisk, currentProject);
} else {
System.out.println("The risk name you trying to access is not registered.");
repeat = true;
}
} while (repeat);
break;
case QUIT_EDIT:
System.out.println("*********************************************************");
break;
default:
System.out.println("Enter the right option");
break;
}
new ProjectManagementTool().pause();
} while (option != QUIT_EDIT);
} else {
System.out.println("There is no registered risk.");
}
} else {
System.out.println("There is no registered project.");
}
}
public void deleteRisk(Risk foundRisk, Project project){ // this methods is handles the risk deletion functions
if(project != null){
final int YES = 1;
int option;
System.out.println("Enter" + " 1 " + "to delete risk,");
System.out.print("Enter any other number to abort. ");
option = new KeyboardInput().Int();
if (option == YES){
project.getRisks().remove(foundRisk);
System.out.println("Risk deleted!.");
} else {
System.out.println("Process aborted.");
}
}
}
public Risk retrieveRegisteredRisk(String riskName, Project project){
if(project != null){
ArrayList<Risk> risks = project.getRisks();
if ( risks != null){
for(Risk risk : risks){
if (risk.getRiskName().equals(riskName)){
return risk;
}
}
}
}
return null;
}
public String readRiskID (){// for new risk ID
String riskID = "";
if(currentProject != null){
System.out.print("Enter new risk ID ");
riskID = new KeyboardInput().Line();
while (retrieveRiskByID(riskID, currentProject.getRisks()) != null){
System.out.println("ID is already registered by other risk.");
System.out.print("Enter another risk ID ");
riskID = new KeyboardInput().Line();
}
}
return riskID;
}
public String checkRiskID (){ // for existing risk ID
String riskID = "";
if(currentProject != null){
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
System.out.println("=================================");
System.out.println(WHITE_UNDERLINED + " List of Risks (ID and Name) " + CYAN_BRIGHT);
for (Risk risk: risks) {
System.out.println(risk.getRiskID() + " :- " + risk.getRiskName());
}
System.out.println();
System.out.print("Form the above list of Risks, enter risk ID ");
riskID = new KeyboardInput().Line();
while (retrieveRiskByID(riskID, risks) == null){
System.out.println("The provided ID does not exist.");
System.out.print("Enter risk ID correctly ");
riskID = new KeyboardInput().Line();
}
} else {
System.out.println("There are no registered risks ");
}
}
return riskID;
}
public String readRiskName (){ // this methods handles all name input requests.
System.out.print("Enter Risk Name: ");
String name = new KeyboardInput().Line();
name = new RiskEvaluator().name(name);
while (retrieveRegisteredRisk(name, currentProject) != null) {
System.out.println();
System.out.println("There exists a risk with the same name use, another name. ");
System.out.println();
System.out.print("Enter new Risk Name.");
name = new KeyboardInput().Line();
name = new RiskEvaluator().name(name);
}
return name;
}
public String readRiskType (){ // read new risk type
String type;
do{
System.out.println(" List of Risk Types");
System.out.println(" 1. PREDICTED ");
System.out.println(" 2. NEW ");
System.out.print("Enter the type of risk (1 or 2 ?) ");
type = new KeyboardInput().Line();
} while (! type.equals("1") && ! type.equals("2") );
if(type.equals("1")){
return "Predicted";
} else {
return " New "; //intentional spaces
}
}
public String readRisk (){ // for Existing risk names
System.out.print("Enter Risk Name :");
String name = new KeyboardInput().Line();
name = new RiskEvaluator().name(name);
return name ;
}
public Risk retrieveRiskByID(String riskID, ArrayList<Risk> risks){
for(int i = 0; i < risks.size(); i++){
Risk currentRisk = risks.get(i);
if(currentRisk.getRiskID().equals(riskID)){
return currentRisk;
}
}
return null;
}
public void printRiskMatrix(){
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
System.out.println(" IMPACT");
System.out.println(" ʌ");
System.out.println(" │");
System.out.print(" │");
for(int i = IMPACT_SCALE; i >= INITIAL ;i--){
System.out.println();
if(i == 23){
System.out.print("Extensive │");
} else if (i == 18){
System.out.print(" Major │");
} else if (i == 13){
System.out.print(" Medium │");
} else if (i == 8) {
System.out.print(" Minor │");
} else if (i == 3){
System.out.print("No Impact │");
} else {
System.out.print(" │");
}
for(int j = INITIAL; j < PROBABILITY_SCALE ;j++){
if(i > 20){
System.out.print(ANSI_RED_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 15 && j < 73){
System.out.print(ANSI_YELLOW_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 15 && j > 72){
System.out.print(ANSI_RED_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 10 && j < 25){
System.out.print(ANSI_GREEN_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 10 && j < 97){
System.out.print(ANSI_YELLOW_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 10 && j > 96){
System.out.print(ANSI_RED_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 5 && j < 49){
System.out.print(ANSI_GREEN_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if(i > 5 && j > 48){
System.out.print(ANSI_YELLOW_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
} else if (i <= 5){
System.out.print(ANSI_GREEN_BACKGROUND);
printMatrixField(i, j);
System.out.print(CYAN_BRIGHT);
}
}
sideLegend(i);
}
System.out.println();
System.out.println(" ────────────────────────.───────────────────────.───────────────────────.───────────────────────.───────────────────────.──────>");
System.out.println(" │ Highly Unlikely │ Unlikely │ Possible │ Likely │ Very Likely │ PROBABILITY");
System.out.println();
System.out.println();
System.out.println(" LEGEND: ");
System.out.println(" " + ANSI_GREEN_BACKGROUND + " " + CYAN_BRIGHT + " Low Severity (Acceptable)");
System.out.println(" " + ANSI_YELLOW_BACKGROUND + " " + CYAN_BRIGHT + " Medium Severity ");
System.out.println(" " + ANSI_RED_BACKGROUND + " " + CYAN_BRIGHT + " High Severity (Not Acceptable)");
System.out.println();
System.out.println(" * single Risk plot ");
System.out.println(" ℗ more than one Risk plot ");
System.out.println(" Side Legends RiskID: (probability, Impact) ");
}
}
public void printMatrixField(int i, int j){
int impact, prob;
int counter = 0;
ArrayList<Risk> risks = currentProject.getRisks();
for (Risk risk:risks) {
impact = (int) Math.round(risk.getImpact() / IMPACT_LIMIT * IMPACT_SCALE);
if (impact == i){
prob = (int) Math.round(risk.getProbability() * PROBABILITY_SCALE);
if (prob == j){
counter = counter + 1;
}
}
}
if(counter == INITIAL){
System.out.print(" ");
} else if (counter == FIRST){
System.out.print(BLACK_BOLD + "*");
} else {
System.out.print(BLACK_BOLD + "℗");
}
}
public void sideLegend(int index){
int impact;
int counter = 0;
ArrayList<Risk> risks = currentProject.getRisks();
for (Risk risk:risks) {
impact = (int) Math.round(risk.getImpact() / IMPACT_LIMIT * IMPACT_SCALE);
if (impact == index){
if(counter == INITIAL){
System.out.print(" ID " + risk.getRiskID() + ": (" +
risk.getProbability() + ", " + risk.getImpact() + ")");
}else {
System.out.print(" , " + risk.getRiskID() + ": (" +
risk.getProbability() + ", " + risk.getImpact() + ")");
}
counter = counter + 1;
}
}
}
public void printSpecificRisk (){
int INDENT1 = 3;
int INDENT2 = 2;
int INDENT3 = 4;
int INDENT4 = 6;
int INDENT5 = 10;
int INDENT6 = 8;
int INDENT7 = 7;
int MIN_INDENT = 12;
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
int indent = foundRisk.getRiskName().length() + foundRisk.getRiskID().length() + INDENT1 ;
if(indent < MIN_INDENT){
indent = MIN_INDENT;
}
int before = (indent - MIN_INDENT)/INDENT1;
int after = indent - MIN_INDENT - before + INDENT2;
System.out.println(WHITE_UNDERLINED);
printEmpty(before);
System.out.print("NAME OF RISK & (ID)");
printEmpty(after - INDENT1);
System.out.print("PROBABILITY");
printEmpty(INDENT3);
System.out.print("IMPACT");
printEmpty(INDENT3);
System.out.print("RISK");
printEmpty(INDENT5);
System.out.print("TYPE");
printEmpty(MIN_INDENT);
System.out.print("STATUS ");
System.out.println(CYAN_BRIGHT);
System.out.print(foundRisk.getRiskName() + " (" + foundRisk.getRiskID() + ")");
int afterName = indent - foundRisk.getRiskName().length();
printEmpty(afterName);
printEmpty(INDENT4);
System.out.print(String.format("%.2f", foundRisk.getProbability()));
printEmpty(INDENT6);
System.out.print(String.format("%.1f", foundRisk.getImpact()));
printEmpty(INDENT4);
System.out.print(String.format("%.2f", foundRisk.getCalculatedRisk()));
printEmpty(INDENT6);
System.out.print(foundRisk.getRiskType());
printEmpty(INDENT7);
System.out.print(foundRisk.getRiskStatus());
System.out.println();
}
public void printEmpty(int spaces){
for(int i = 0; i<spaces; i++){
System.out.print(" ");
}
}
public void printAllRisks(){
int INDENT1 = 3;
int INDENT2 = 2;
int INDENT3 = 4;
int INDENT4 = 6;
int INDENT5 = 8;
int INDENT6 = 11;
int MIN_INDENT = 12;
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
int indent = risks.get(INITIAL).getRiskName().length();
for (Risk currentRisk : risks){
int newIndent = currentRisk.getRiskName().length() + currentRisk.getRiskID().length() + INDENT1;
if ( newIndent > indent) {
indent = newIndent;
}
}
if(indent < MIN_INDENT){
indent = MIN_INDENT;
}
int before = (indent - MIN_INDENT)/INDENT1;
int after = indent - MIN_INDENT - before + INDENT2;
System.out.println(WHITE_UNDERLINED);
printEmpty(before);
System.out.print("NAME OF RISK & (ID)");
printEmpty(after - INDENT1);
System.out.print("PROBABILITY");
printEmpty(INDENT3);
System.out.print("IMPACT");
printEmpty(INDENT3);
System.out.print("RISK");
printEmpty(INDENT5);
System.out.print("TYPE");
printEmpty(INDENT6);
System.out.print("STATUS ");
System.out.println(CYAN_BRIGHT);
for ( Risk foundRisk : risks) {
System.out.print(foundRisk.getRiskName() + " (" + foundRisk.getRiskID() + ")");
int afterName = indent - foundRisk.getRiskName().length();
printEmpty(afterName);
printEmpty(INDENT4);
System.out.print(String.format("%.2f", foundRisk.getProbability()));
printEmpty(INDENT5);
System.out.print(String.format("%.1f", foundRisk.getImpact()));
printEmpty(INDENT4);
System.out.print(String.format("%.2f", foundRisk.getCalculatedRisk()));
printEmpty(INDENT4);
System.out.print(foundRisk.getRiskType());
printEmpty(INDENT4);
System.out.print(foundRisk.getRiskStatus());
System.out.println();
}
} else {
System.out.println("There is no registered risk.");
}
}
public void printNumberOfRisk(){
int numberOfRisks;
if(currentProject != null){
ArrayList<Risk> risks = currentProject.getRisks();
if (risks!=null){
numberOfRisks = risks.size();
if (numberOfRisks == FIRST){
System.out.println("*******************************");
System.out.println("There is " + risks.size() + " registered risk.");
} else {
System.out.println("*******************************");
System.out.println("There are " + risks.size() + " registered risks.");
}
} else {
System.out.println("There is no registered risk.");
}
}
}
public void percentageConverter(){ // this methods handles the converting to percentage function.
final int PROBABILITY = 1;
final int IMPACT = 2;
final int QUIT = 3;
int option ;
if(currentProject != null){
ArrayList<Risk> risks = currentProject.getRisks();
if(risks != null){
do {
System.out.println("1. CONVERT PROBABILITY");
System.out.println("2. CONVERT IMPACT.");
System.out.println("3. QUIT");
option = new KeyboardInput().positiveInt();
switch (option) {
case PROBABILITY:
probabilityPercentage();
System.out.println("*************************************");
break;
case IMPACT:
impactPercentage();
System.out.println("*************************************");
break;
case QUIT:
System.out.println("*************************************");
break;
default:
System.out.println("Enter a valid input");
break;
}
} while (option != QUIT);
}else {
System.out.println("There are no registered risks ");
}
}
}
public void probabilityPercentage(){ // this method coverts probability value of a given risk to percentage value.
final double fixedProbability = 10.0;
double maxPercentage = 100.0;
if(currentProject != null){
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if(foundRisk != null){
double foundProbability = foundRisk.getProbability();
double convertedProbability = (foundProbability/fixedProbability) * maxPercentage;
System.out.println("The risk " + foundRisk.getRiskName() + " has a probability of " + convertedProbability
+ " %");
} else{
System.out.println("The risk name does not exist.");
}
}
}
public void impactPercentage(){ // this method converts impact values of a given risk to percentage values.
final double fixedImpact = 10.0;
double maxPercentage = 100.0;
if(currentProject != null){
String riskID = checkRiskID();
Risk foundRisk = retrieveRiskByID(riskID, currentProject.getRisks());
if (foundRisk != null){
double foundImpact = foundRisk.getImpact();
double convertedImpact = (foundImpact/fixedImpact) * maxPercentage;
System.out.println("The risk "+ foundRisk.getRiskName() + " has an impact of "+ convertedImpact + " %");
} else {
System.out.println("The risk name does not exist");
}
}
}
}