/** * CSE 373, Spring 2011, Jessica Miller * This client tests the get and remove methods of the HashMap. These are not * necessarily comprehensive tests, so you should add further tests to this file * for unchecked cases. */ public class HashMapClient { private static final String[] countries = {"United Arab Emirates", "Thailand", "Germany", "Brazil", "Hungary", "Wales", "Jamaica", "Nepal", null, "Vatican City"}; private static final String[] capitals = {"Abu Dabi", "Bangkok", "Berlin", "Brasilia", "Budapest", "Cardiff", "Kingston", "Kathmandu", "unknown", null}; public static void main(String[] args) { testGet(); System.out.println(); testRemove(); // ADD MORE TESTS HERE! } public static void testGet() { System.out.println("----- TESTING MAP'S GET METHOD -----"); Map m = getMap(); for (int i = 0; i < countries.length; i++) { System.out.println(countries[i] + "'s capital is..." + m.get(countries[i])); } } public static void testRemove() { System.out.println("----- TESTING MAP'S REMOVE METHOD -----"); Map m = getMap(); System.out.println("Map before any removals:"); m.print(); System.out.println(); for (int i = 0; i < countries.length; i++) { String capital = m.remove(countries[i]); System.out.println("Removing " + countries[i] + " returns " + capital + "."); System.out.println("Map after removing " + countries[i] + ":"); m.print(); System.out.println(); } } private static Map getMap() { Map map = new HashMap(); for (int i = 0; i < countries.length; i++) { map.put(countries[i], capitals[i]); } return map; } }