Advertisement
Guest User

Candidate Class

a guest
Mar 22nd, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. /**
  2.  * Purpose:  This class defines a Candidate by its name and number of votes.
  3.  *
  4.  * @author Blake
  5.  * @version 3/22/18
  6.  */
  7.  
  8. public class Candidate
  9. {
  10.     // instance variables
  11.     private int numVotes;
  12.     private String name;
  13.  
  14.     // Constructor for objects of class Candidate
  15.     public Candidate(String name, int numVotes)
  16.     {
  17.         // initialize instance variables
  18.         this.name = name;
  19.         this.numVotes = numVotes;
  20.     }
  21.  
  22.     public String getName()
  23.     {
  24.         return name;
  25.     }
  26.  
  27.     public int getVotes()
  28.     {
  29.         return numVotes;
  30.     }
  31.  
  32.     public void setVotes(int n)
  33.     {
  34.         numVotes = n;
  35.     }
  36.  
  37.     public void setName(String n)
  38.     {
  39.         name = n;
  40.     }
  41.  
  42.     public String toString()
  43.     {
  44.         return name + " received " + numVotes + " votes.";
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement