/**
 * @author Haiping Xu
 * Created at the CIS Department, UMass Dartmouth
 */

import java.util.Random;

// The class Vote1 implements the Runnnable interface
public class Vote1 implements Runnable {
    private String response;

    public Vote1(String newResponse){
        response = newResponse;
    }

    public void run(){
        final int REPETITIONS = 5;
        Random random = new Random();
        int delay = 0;

        for (int i=0; i<REPETITIONS; i++){
            delay = random.nextInt(1000);
            try {
                Thread.sleep(delay);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(response);
        }
    }

    // Thread Creation 2: A thread can be created by passing a Runnable object
    // to a new Thread instance. The object's run() method will be invoked
    // automatically as soon as the thread's start() method is called.
    public static void main(String[] args) {
        Thread yes, no;

        yes = new Thread(new Vote1("Yes -- Thread 1"));
        no = new Thread(new Vote1("No  -- Thread 2"));

        yes.start();
        no.start();
    }
}
