Sorting Objects.
Whats the best/easyiest/efficient!! etc way to sort through and find the object with the highest score?
heres my the constructor for the object class,
public Candidates(String LastName,String FirstName, String PartyName,double Votes ){
heres the sortin algorithim im tryin to use.
public Candidates FindElected(){
int i,j;
Candidates aCandidate, bCandidate, tempCandidate;
for (i=1; i<CandidateVector.size(); i++){
for (j=0; j><CandidateVector.size()-i; j++){
aCandidate = (Candidates)CandidateVector.elementAt(j);
bCandidate = (Candidates)CandidateVector.elementAt(j+1);
if (aCandidate.getVotes() > bCandidate.getVotes()){// compare the two neighbors
tempCandidate =new Candidates();
tempCandidate.equals(aCandidate);/* swap a[j] and a[j+1]
*/
CandidateVector.insertsetElementAt((Candidates)bCandidate,(int)j);
CandidateVector.setElementAt((Candidates)tempCandidate,(int)j+1);
}// end of if
}// end of second for
}// end of first for
int index;
for (index = 0; index < CandidateVector.size(); index++ )
{
aCandidate =(Candidates)CandidateVector.elementAt(index);
System.out.println("Candidate " + index +"" + aCandidate.getLastName());
}
return (Candidates)CandidateVector.lastElement();
The results i get are either wrong, null or exception is thrown.
I think Im on the right track though
Any suggestions.
Ass always cheers!

