Ejemplo n.º 1
0
  public void vote(String voterId, String partyName, String candidateId)
      throws VotableNotFoundException, InvalidVoterException, MultipleVoteException {
    if (votables.size() == 0) {
      throw new VotableNotFoundException();
    }
    Person voter = null;
    Votable party = null, candidate = null;
    for (int i = 0; i < people.size(); i++) {
      if (people.get(i).getSocialID().equals(voterId)) {
        voter = people.get(i);
        if (voted.get(i)) {
          throw new MultipleVoteException();
        } else {
          voted.set(i, true);
        }
        break;
      }
    }
    if (voter == null || !voter.isEligibleToVote()) {
      throw new InvalidVoterException();
    }

    for (int i = 0; i < votables.size(); i++) {
      if (votables.get(i).getId().equals(partyName)) {
        party = votables.get(i);
      }
      if (votables.get(i).getId().equals(candidateId)) {
        candidate = votables.get(i);
      }
    }
    if (partyName != "") {
      if (party != null) {
        party.giveVote();
      } else {
        throw new VotableNotFoundException();
      }
    }
    if (candidateId != "") {
      if (candidate != null) {
        candidate.giveVote();
      } else {
        throw new VotableNotFoundException();
      }
    }
  }
Ejemplo n.º 2
0
 public int countVotes(Votable votable) {
   return votable.countVotes();
 }