E-Voting Program

The following program is a very simple prototype of an e-voting program.  

import java.awt.*;

public class Voting extends EasyApp
{
   public static void main(String[] args)
   {
      new Voting();
   }
   
   String[] candidates = {"Angela","Bill","Chuckles"};
   int[] votes = {0,0,0};
   
   Button first  = addButton(candidates[0],50,50,100,50,this);
   Button second = addButton(candidates[1],150,50,100,50,this);
   Button third  = addButton(candidates[2],250,50,100,50,this);   
   Button results= addButton("Results",150,150,100,50,this);
   
   public void actions(Object source, String command)
   {
      if (source == first)
      {
         votes[0] = votes[0] + 1;
      }
       if (source == second)
      {
         votes[1] = votes[1] + 1;
      }
      if (source == third)
      {
         votes[2] = votes[2] + 1;
      }
      if (source == results)
      {
         String id = input("Type the secret password");
         if (id.equals("results"))
         {
            for (int x = 0; x < candidates.length; x = x+1)
            {
               output(candidates[x] + " = " + votes[x]);   
            }
            
         }
      }
   }
}

-- Everything is Replaceable --

The prototype displays a basic concept and a basic structure for the program.  Any part of the program can be changed or replaced.  Nothing is "etched in stone."   

The most obvious things that are changeable are all the red text.  That is, all the constant (literal) values of Strings and numbers.  The most obvious of all are the candidate's names.  

- Try This -

All the useful changes involve "what if" questions.

  1. What happens if you change one of the candidates' names?  Does the program still work correctly?
  2. What if you change the order of the candidate names?  Does it still work (correctly)?
  3. What if you remove one of the candidates' names?  Does it still work correctly?
  4. What if you add some more names?  Does it still work correctly?
  5. What if you change the secret password?  Does it still work correctly?

Improvements often involve error-handling - "what can go wrong"?

  1. What goes wrong if you press the wrong button?  How can it be fixed?
  2. What goes wrong if you want to vote for someone else (write-in)?  How can it be fixed?

The useful additions (improvements) involve "how can it" questions.

  1. How can it add more buttons for more candidates?
  2. How can it save the results and re-load them later (to continue where it left off)?
  3. How can the computer decide who the winner is?

Keep in mind that everything is replaceable.  For example, it needs to be possible to replace the {array} containing candidate names with a method that reads the names from a file.