Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.List;
- public class Candidate implements CandidateInterface {
- private String firstName;
- private String lastName;
- private int voteCount;
- private int addVote;
- public Candidate(String inFirstName, String inLastName, int voteCount) {
- firstName = inFirstName;
- lastName = inLastName;
- addVote = 0;
- voteCount = 0;
- }
- public String getFirstName() {
- return firstName;
- }
- public String getLastName() {
- return lastName;
- }
- public int getAddVote() {
- return addVote;
- }
- public int getVoteCount() {
- return voteCount;
- }
- @Override
- public void addVote() {
- voteCount++;
- }
- @Override
- public boolean equals(Object something) {
- Candidate another = (Candidate) something;
- if( ! firstName.equals(another.firstName)) {
- return false;
- }
- if( ! lastName.equals(another.lastName)) {
- return false;
- }
- return true;
- public int compareTo(Candidate another) {
- int myTotalVotes = getTotalVotes();
- int otherTotalVotes = another.getTotalVotes();
- int difference = myTotalVotes - otherTotalVotes;
- if(difference != 0) {
- return difference;
- }
- difference = firstName.compareTo(another.getFirstName());
- return difference;
- }
- }
- }
Add Comment
Please, Sign In to add comment