-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathAntCUI.java
More file actions
105 lines (100 loc) · 4.04 KB
/
AntCUI.java
File metadata and controls
105 lines (100 loc) · 4.04 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
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
/**
* Console user interface for decision support application.
*
* @author Dr. Jody Paul
* @version 20241114.1
*/
public class AntCUI extends UserInterface {
@Override
public void showIntroduction() {
System.out.println(INTRODUCTION);
}
@Override
public List<Alternative> getAlternatives() {
List<Alternative> alternativeList = new ArrayList<Alternative>();
Scanner sc = new Scanner(System.in);
System.out.println(FIRST_ALT_PROMPT + ": ");
String alternative = sc.nextLine();
while (alternative != null && !("".equals(alternative))) {
alternativeList.add(new Alternative(alternative));
System.out.println(ADDITIONAL_ALT_PROMT + ": ");
alternative = sc.nextLine();
}
return alternativeList;
}
@Override
public List<Factor> getFactors() {
List<Factor> factorList = new ArrayList<Factor>();
Scanner sc = new Scanner(System.in);
System.out.println(FIRST_FACTOR_PROMPT + ": ");
String factor = sc.nextLine();
while (factor != null && !("".equals(factor))) {
factorList.add(new Factor(factor));
System.out.println(ADDITIONAL_FACTOR_PROMPT);
factor = sc.nextLine();
}
return factorList;
}
@Override
public void getFactorRankings(final List<Factor> factors,
final int standard) {
Scanner sc = new Scanner(System.in);
int firstAttribute = 0;
factors.get(firstAttribute).setRank(standard);
System.out.println("\n\nAssume that "
+ factors.get(firstAttribute).getName()
+ " has an importance of " + standard + ",\n"
+ " and that higher values are more important.\n");
for (int i = firstAttribute + 1; i < factors.size(); i++) {
System.out.println(" How important is "
+ factors.get(i).getName() + "? ");
String importance = sc.nextLine();
if (importance == null || "".equals(importance)) {
factors.get(i).setRank(standard);
} else {
factors.get(i).setRank(Integer.valueOf(importance));
}
}
}
@Override
public double[][] getCrossRankings(final List<Alternative> alternatives,
final List<Factor> factors,
final int standard) {
Scanner sc = new Scanner(System.in);
double[][] crossRankings =
new double[alternatives.size()][factors.size()];
for (int i = 0; i < factors.size(); i++) {
int firstAlternative = 0;
crossRankings[firstAlternative][i] = standard;
System.out.println("\n\nConsidering " + factors.get(i).getName()
+ " only...");
System.out.println(" if "
+ alternatives.get(firstAlternative).getDescriptor()
+ " has a value of " + standard + "... ");
for (int j = firstAlternative + 1; j < alternatives.size(); j++) {
System.out.println(" ...what value would you associate"
+ "with " + alternatives.get(j).getDescriptor() + ": ");
String rank = sc.nextLine();
if (rank == null || "".equals(rank)) {
crossRankings[j][i] = standard;
} else {
crossRankings[j][i] = Integer.valueOf(rank);
}
}
}
return crossRankings;
}
@Override
public void showResults(final List<Alternative> alternatives) {
Alternative preferredAlternative = alternatives.get(0);
System.out.println("\n\n================\nPreferred choice: ");
System.out.println(preferredAlternative.getDescriptor());
System.out.println("-----");
for (Alternative a : alternatives) {
System.out.println(a);
}
}
}