Guest User

Untitled

a guest
Jun 19th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3.  
  4. public class Candidate implements CandidateInterface {
  5.     private String firstName;
  6.     private String lastName;
  7.     private int voteCount;
  8.     private int addVote;
  9.  
  10.     public Candidate(String inFirstName, String inLastName, int voteCount) {
  11.         firstName = inFirstName;
  12.         lastName = inLastName;
  13.  
  14.         addVote = 0;
  15.         voteCount = 0;
  16.     }
  17.  
  18.     public String getFirstName() {
  19.         return firstName;
  20.     }
  21.  
  22.     public String getLastName() {
  23.         return lastName;
  24.     }
  25.  
  26.     public int getAddVote() {
  27.         return addVote;
  28.     }
  29.  
  30.     public int getVoteCount() {
  31.         return voteCount;
  32.     }
  33.    
  34.     @Override
  35.     public void addVote() {
  36.         voteCount++;
  37.     }
  38.  
  39.     @Override
  40.             public boolean equals(Object something) {
  41.                     Candidate another = (Candidate) something;
  42.                    
  43.                     if( ! firstName.equals(another.firstName)) {
  44.                                     return false;
  45.                             }
  46.                    
  47.                     if( ! lastName.equals(another.lastName)) {
  48.                             return false;
  49.                     }
  50.                    
  51.                     return true;
  52.                    
  53.              public int compareTo(Candidate another) {
  54.                         int myTotalVotes = getTotalVotes();
  55.                         int otherTotalVotes = another.getTotalVotes();
  56.                        
  57.                         int difference = myTotalVotes - otherTotalVotes;
  58.                        
  59.                         if(difference != 0) {
  60.                                 return difference;
  61.                         }
  62.                        
  63.                         difference = firstName.compareTo(another.getFirstName());
  64.                        
  65.                         return difference;
  66.                 }
  67.  
  68.             }
  69. }
Add Comment
Please, Sign In to add comment