/**
 * @author Haiping Xu
 * Created at the CIS Department, UMass Dartmouth
 */

import java.util.Random;

public class DiffTasks implements Runnable {
    private int choice;

    public DiffTasks(int newChoice){
        choice = newChoice;
    }

    private void delay() {
        Random random = new Random();
        int delay = 0;
        delay = random.nextInt(1000);
        try {
            Thread.sleep(delay);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void run(){
        final int REPETITIONS = 5;

        switch (choice) {
          case 1:      // task 1
              for (int i=0; i<REPETITIONS; i++) {
                   delay();
                  System.out.println("Do-Task-" + choice + " ");
              }
              break;
          case 2:      // task 2
              for (int i=0; i<REPETITIONS; i++){
                  delay();
                  System.out.println("Do-Task-" + choice + " ");
              }
              break;
          default:     // task whatever
              delay();
              System.out.println("Do-Whatever-Task");
        }
    }

    public static void main(String[] args) {
        Thread task1, task2, taskx;

        task1 = new Thread(new DiffTasks(1));
        task2 = new Thread(new DiffTasks(2));
        taskx = new Thread(new DiffTasks(9));

        task1.start();
        task2.start();
        taskx.start();
    }
}
