
import java.io.*;

// A ward contains instance variables for
//          - its name
//          - votes for each candidate
//          - total votes in the ward
//
// It has service methods for
//          - voting for a candidate
//          - printing the results
//
public class Ward {

   private String name;
   private int votesFor1 = 0;
   private int votesFor2 = 0;
   private int votesFor3 = 0;

   private int totalVotes = 0;

   // Constructor -- initializes the name of ward
   public Ward (String name_of_ward) {
      name = name_of_ward;
   }

   // add a vote for the specified candidate
   public void voteFor (int cand) {
      if (cand == 1) {
	 votesFor1 ++;    // ++ operator increments the variables by
      }
      else if (cand == 2) {
	 votesFor2 ++;
      }
      else if (cand == 3) {
	 votesFor3 ++;
      }
      else System.out.println("Unknown candidate");

      totalVotes ++;
   }

   // print out percentages to see who won
   public void printResults() {
      System.out.println("Results for ward: " + name);
      System.out.println("----------------------------------");
      System.out.println("Candidate 1 got " + 100*votesFor1/totalVotes + "%");
      System.out.println("Candidate 2 got " + 100*votesFor2/totalVotes + "%");
      System.out.println("Candidate 3 got " + 100*votesFor3/totalVotes + "%");
   }
}

