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.
Improvements often involve error-handling - "what can go wrong"?
The useful additions (improvements) involve "how can it" questions.
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.