import java.util.List; import java.util.ArrayList; //------------------------------------------------------------------------- /** * This class represents a rudimentary gradebook that contains a set * of student records. It is not very complete yet, but should serve * as an example. * * @author Stephen Edwards * @version Feb 22, 2013 */ public class Gradebook { //~ Instance/static variables ............................................. private List students; //~ Constructor ........................................................... // ---------------------------------------------------------- /** * Creates a new Gradebook object. The gradebook is initially empty. */ public Gradebook() { students = new ArrayList(); } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Add another student record to this gradebook. * @param student the new student record to add */ public void addStudent(Student student) { students.add(student); } // ---------------------------------------------------------- /** * Look up a student record by name in this gradebook. * @param name the name of the student to find * @return the student record, if found, or null if no student record * with the given name is found */ public Student findStudent(String name) { for (Student student : students) { if ((name == null && student.name() == name) || name.equals(student.name())) { return student; } } return null; } }