Created
February 9, 2012 03:28
-
-
Save andrelashley/1777022 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.jar.Attributes.Name; | |
public class Candidate implements CandidateInterface{ | |
private String firstName; | |
private String lastName; | |
private int voteCount; | |
public Candidate(String inFirstName, String inLastName){ | |
firstName = inFirstName; | |
lastName = inLastName; | |
voteCount = 0; | |
} | |
@Override | |
public boolean equals(Object who){ | |
Candidate otherCandidate = (Candidate) who; | |
if(! firstName.equals(otherCandidate.getFirstName())){ | |
return false; | |
} | |
if(! lastName.equals(otherCandidate.getLastName())){ | |
return false; | |
} | |
return true; | |
} | |
@Override | |
public int compareTo(CandidateInterface other) { | |
int difference = voteCount - other.getVoteCount(); | |
if(difference != 0){ | |
return difference; | |
} | |
if(lastName.equals(other.getLastName())){ | |
return firstName.compareTo(other.getFirstName()); | |
} | |
return lastName.compareTo(other.getLastName()); | |
} | |
@Override | |
public void addVote() { | |
voteCount++; | |
} | |
@Override | |
public int getVoteCount() { | |
return voteCount; | |
} | |
@Override | |
public String getFirstName() { | |
return firstName; | |
} | |
@Override | |
public String getLastName() { | |
return lastName; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment