import java.io.*; import java.util.*; public class Sample { public static void main(String args[]) { ArrayList a = new ArrayList(); a.add("James"); a.add("John"); a.add("Chris"); a.add("Charlie"); a.add("Donald"); a.add("Michael"); if (findName(a,"Jones")) System.out.println("Jones is in the array list"); else System.out.println("Jones is not in the array list"); if (findName(a,"Donald")) System.out.println("Donald is in the array list"); else System.out.println("Donald is not in the array list"); Map gpaMap = new HashMap(); gpaMap.put("Michael",new Double(4.0)); gpaMap.put("Charlie",new Double(3.0)); gpaMap.put("Chris",new Double(3.5)); gpaMap.put("Donald",new Double(2.2)); Double chrisGPA = getGPA(gpaMap,"Chris"); if (chrisGPA != null) System.out.println("Chris has a gpa of "+chrisGPA); else System.out.println("Chris does not have an entry in the Map"); Double jonesGPA = getGPA(gpaMap,"Jones"); if (jonesGPA != null) System.out.println("Jones has a gpa of "+jonesGPA); else System.out.println("Jones does not have an entry in the Map"); } // Search array list for a name public static boolean findName(ArrayList a, String searchName) { for (int i=0; i gpaMap, String searchName) { return gpaMap.get(searchName); } // Print all Student names and their GPAs public static void printGPAs(Map gpaMap) { for (Map.Entry entry : gpaMap.entrySet()) { System.out.println("Student Name: "+entry.getKey()+" GPA: "+entry.getValue()); } } }