So I got a treemap to which I add courses that come from a random generator, the names are consistent but the order is not. For example I got these:
List course = new ArrayList();
course.add("COP2210");
course.add("COP2250");
course.add("ENC1250");
course.add("MLP1337");
course.add("ENC3250");
course.add("REL2210");
course.add("MUS3200");
course.add("PHI1240");
course.add("SOL5000");
course.add("HAL9000");
Now that's ten courses in total, and while the code below works to count one of them it would mean i have to get about nine more int variables written and repeat the if statement another nine times, that would be undesirable. I should mention the treemap is inside a loop and resets everytime, which is something I want. but a second treemap can be made outside the loop to add the courses, i got no issue with that. But it is entirely possible that some courses never even gets added to the treemap as they are randomly chosen from the ten above.
for (int i = 0; i < NumberOfStudents; ++i){
order = RandomCourse();
TreeMap<String, Integer> tmap = new TreeMap<String, Integer>();
tmap.put(courses.get(order[0]).toString(), 0);
tmap.put(courses.get(order[1]).toString(), 0);
tmap.put(courses.get(order[2]).toString(), 0);
String comparator1 = courses.get(order[0]).toString();
String comparator2 = courses.get(order[1]).toString();
String comparator3 = courses.get(order[2]).toString();
if(comparator1 == "HAL9000" || comparator2 == "HAL9000" || comparator3 == "HAL9000")
HAL9000students++;
courses.indexOf(order[0]);
//Clean variable
SortedCourses = "";
//Map logic
Set set = tmap.entrySet();
Iterator iterator = set.iterator();
while(iterator.hasNext()) {
Map.Entry mentry = (Map.Entry)iterator.next();
SortedCourses = SortedCourses + mentry.getKey() + " ";
}
students.add(ID_Prefix + i+ ", " + student.get(i) + " " + SortedCourses);
}
Order is a int array of size 3. Where a random number is stored, it is then used to choose from courses list a position which corresponds to a course.