package edu.columbia.cs.cs1007.roster;
/**
* Implementation of the Student object.
*
* @author Julia Stoyanovich (jds2109@columbia.edu)
* COMS 1007, Summer 2009
*
*/
public class Student implements Comparable<Student> {
private String _name;
private String _uni;
private int _gradYear;
private String _major;
/**
* Constructor
* @param uni - unique identifier
* @param name
* @param year - graduation year
* @param major
*/
public Student(String uni, String name, int year, String major) {
_uni = uni.trim();
_name = name.trim();
_gradYear = year;
_major = major.trim();
}
/**
* Generate a string representation of the student.
* @return string representation
*/
public String toString() {
return _name + "(" + _uni + ")" + " " + _major + " " + _gradYear;
}
/**
* Accessor.
* @return uni
*/
public String getUni() {
return _uni;
}
/**
* Accessor.
* @return major
*/
public String getMajor() {
return _major;
}
/**
* Accessor.
* @return graduation year
*/
public int getGradYear() {
return _gradYear;
}
/**
* Override the equals() method of the Object class.
* Two student are equal if they have the same uni.
*/
public boolean equals(Object other) {
if ((other == null) || !(other instanceof Student)) {
return false;
}
Student that = (Student)other;
return _uni.equalsIgnoreCase(that._uni);
}
/**
* Override the hashCode() method of the Object class.
* Hashcode is generated based on the uni.
*/
public int hashCode() {
return _uni.toLowerCase().hashCode();
}
/**
* Implementation of the compareTo(Student that) method
* required by the Comparable interface.
* Comparison is based on the uni.
*/
public int compareTo(Student that) {
return _uni.compareTo(that._uni);
}
}
|