public class Class { private final List students; /** * Throws IllegalArgumentException if any of the students are null */ public Class(List students) { for (Student student : students) { if (student == null) { throw new IllegalArgumentException(); } } this.students = students; } public List getStudents() { return students; } public void printClassRoster() { for (Student student : students) { // there shouldn't be any null students here System.out.println(student.getName() + " " + student.getGPA()); } } } /** * Write client code using Class and Student that will cause printClassRoster to throw a NullPointerException. * * One possible solution: * public static void badClient() { * List students = ...; //Initialize a list. * Class cse373 = new Class(students); * class.printClassRoster(); // This is fine * students.add(null); * class.printClassRoster(); // NullPointerException * } * * What changes need to be made to these classes to preserve abstractions for the entire Class class? * Note you might have to change Student too. * * Solution: * Make a copy of the given list in the constructor * Make a copy of the list in getStudents to return * Make the Student fields private * Either make the Student fields final or also make copies of each individual Student in the Class constructor and getStudents. */