import java.util.Hashtable; import java.util.Enumeration; /** a demo of Hashtables in Java @author P. Conrad @version CS56, W11, UCSB */ public class GradeDictDemo { public static void main(String [] args) { Hashtable gradeDict = new Hashtable(); gradeDict.put("A",4.0); gradeDict.put("A-",3.7); gradeDict.put("B+",3.3); gradeDict.put("B",3.0); gradeDict.put("B-",2.7); // TODO: fill in the rest--this is enough to get the point across System.out.println("Here's how to look up the value of a grade:"); String grade = "B+"; System.out.println(" Grade = " + grade + " Value = " + gradeDict.get(grade)); // Iterating System.out.println("Grade table"); Enumeration e = gradeDict.keys(); while (e.hasMoreElements()) { String k = e.nextElement() ; System.out.println(" grade: " + k + " value: " + gradeDict.get(k)); } } }