/* File Name: StudentList.java * * Purpose: Main class which runs the program * * Name: Haresh Modha * * Instructor: Leonidas Deligiannidis, Ph.D. */ public class StudentList { private StudentNode list; /* * Sets up an initially empty list of students */ public StudentList() { list = null; } /* * Creates a new StudentNode object and adds it to the end of the linked list */ public void add (Student stu) { StudentNode node = new StudentNode (stu); StudentNode current; if (list == null) { list = node; } else { current = list; while (current.next != null) { current = current.next; } current.next = node; } } /* * Returns this list of students as a string */ public String toString () { String result = ""; StudentNode current = list; while (current != null) { result += current.student + "\n"; current = current.next; } return result; } /* * An inner class that represents a node in the student list. * The public variables are accessed by the StudentList class. */ private class StudentNode { public Student student; public StudentNode next; //Sets up the node public StudentNode (Student stu) { student = stu; next = null; } } }