I have a super class Student and subclasses Undergraduate_Student and Graduate_Student. All types of students have an Age, SocialSecurity & Name attribute. I'm trying to make comparator classes to sort according to those attribues, but they aren't sorting.
Here's some of my code:
class NameComparator implements Comparator {
public int compare(Object student, Object anotherStudent) {
String name1;
String name2;
if(anotherStudent instanceof Undergraduate_Student)
{ name1 = ((Undergraduate_Student) student).name.toUpperCase();
name2 = ((Undergraduate_Student) anotherStudent).name.toUpperCase();
}
else
{
name1 = ((Graduate_Student) student).name.toUpperCase();
name2 = ((Graduate_Student) anotherStudent).name.toUpperCase();
}
return name1.compareTo(name2);
}
} // end class NameComparator
2007-02-13
16:28:36
·
1 answers
·
asked by
Kanayo
2
in
Computers & Internet
➔ Programming & Design