Skip to content

Instantly share code, notes, and snippets.

@andrelashley
Created February 9, 2012 03:28
Show Gist options
  • Save andrelashley/1777022 to your computer and use it in GitHub Desktop.
Save andrelashley/1777022 to your computer and use it in GitHub Desktop.
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