Compsci 100e, Spring 2011, Classwork 3

Names and NetID of students in group (min 2, max 3)
Name: __________________________   NetID: _____________

Name: __________________________   NetID: _____________

Name: __________________________   NetID: _____________

Unique Names

Consider the Student class.

public class Student { private String myName; // name of Student private String myYear; // class of student such as first-year, sophomore, etc. public Student(String name, String year) { myName = name; myYear = year; } public String getName() { return myName; } public String getYear() { return myYear; } }

Write the method uniqueNames whose header is given below. This method takes as input an ArrayList of type Student and a year indicator and returns a TreeSet of the unique names of all students whose year matches the year indicator.

For example, if an ArrayList of Student types called Dook contained the following five persons (indicating their name and year):

Ed first-year, Ma sophomore, Jo first-year, Qiang first-year, Jo first-year
then the call uniqueNames(Dook, "first-year") would return a TreeSet containing the strings: "Ed", "Jo" and "Qiang". public TreeSet<String> uniqueNames(ArrayList<Student> people, String year) {