Skip to content

Instantly share code, notes, and snippets.

@andrelashley
Created February 10, 2012 06:55
Show Gist options
  • Save andrelashley/1787281 to your computer and use it in GitHub Desktop.
Save andrelashley/1787281 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
public class Riding implements RidingInterface {
private String ridingName;
private List<CandidateInterface> candidates;
public Riding(String inRidingName) {
candidates = new ArrayList<CandidateInterface>();
ridingName = inRidingName;
}
@Override
public Iterator<CandidateInterface> iterator() {
Collections.sort(candidates);
Collections.reverse(candidates);
return candidates.iterator();
}
@Override
public String getName() {
return ridingName;
}
@Override
public void addCandidate(CandidateInterface who) {
candidates.add(who);
}
@Override
public void voteFor(CandidateInterface fakeWho) {
int candidatePosition = candidates.indexOf(fakeWho);
CandidateInterface foundCandidate = candidates.get(candidatePosition);
foundCandidate.addVote();
}
@Override
public CandidateInterface getWinner() {
return Collections.max(candidates);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment