Created
February 10, 2012 06:55
-
-
Save andrelashley/1787281 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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