// Allison Obourn // CSE 143 - lecture 12 // Outputs a list of TAs by grade. // It demonstrates using a Map mapping something to another collection. import java.util.*; import java.io.*; public class TAgrades { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("tas.txt")); Map> grades = new TreeMap>(); // puts all the grades in the map connected to tas while(input.hasNext()) { String ta = input.next().toLowerCase(); double grade = input.nextDouble(); if(!grades.containsKey(grade)){ grades.put(grade, new TreeSet()); } grades.get(grade).add(ta); } // removes grades below a 3.0 Iterator itr = grades.keySet().iterator(); while(itr.hasNext()) { double grade = itr.next(); if(grade < 3.0) { itr.remove(); } } // iterate over the map using the set of keys for(Double grade : grades.keySet()) { System.out.println(grade + " " + grades.get(grade)); } } }