/* CSE 143, Summer 2012 Processes a map of exam scores removing people who failed the exam. */ import java.util.*; public class ExamScores { public static void main (String[] args) { Map m = new HashMap(); m.put("Allison", 42); m.put("Dane", 90); m.put("Victoria", 78); m.put("Mikey", 70); m.put("Zack", 45); m.put("Charlie", 64); System.out.println(m); removeLessThanN(m, 50); System.out.println(m); } // removes all map entires with a value less than n public static void removeLessThanN (Map m, int n) { // we have to create an iterator over the keySet not the map. // if we try to create an iterator over the map it does not know // whether we want its keys or values Iterator itr = m.keySet().iterator(); while (itr.hasNext()) { if (m.get(itr.next()) < n) { itr.remove(); } } } }