Skip to content
Changwang Zhang edited this page Apr 4, 2016 · 18 revisions

Every application should extend the Task class and implement the application by overriding Task's methods. Fig. 1 shows the default method flow for a task.

Method Flow

Fig. 1. Default method flow and time points for a task.

Blow is an example application RollDice. The application simulates to roll a dice at each step. Each dice has nSide sides, and there are nDice dices. In total it conducts nDice steps in each repeat of a task.

public class RollDice extends Task {
  public Integer nSide; //Number of dice sides
  public Integer nDice; //Number of dices to roll
  public Integer sum;

  public boolean prepTask() {
    boolean rtn = nSide > 0 && nDice > 0;
    return rtn;
  }

  public void beforeRept() {
    super.beforeRept();
    sum = 0;
  }

  public boolean step() {
    boolean rtn = iStep <= nDice;
    if (rtn) {
      sum += (int) (rand.nextDouble() * nSide + 1);
    }
    return rtn;
  }
}

Clone this wiki locally