EJS is a java code generator. It is not designed for professional programmer. It is designed for user who know about the physics model but lack of programming skill and detail java programming. But the user need to understand basic program structure and logic. It has build in GUI interface so that user can use it directly. User just need to assign properties to variables/values defined in EJS. EJS also has build it numerical solver to do numerical integration for you.
Please check out [url=http://www.phy.ntnu.edu.tw/ntnujava/index.php?board=11.0]Information and Download[/url] for related information and documents. There are pdf files and html pages about EJS, please read it first.
You would not be able to define class in EJS. But you can write your own java class and import into EJS.
I used to write java code line by line (befroe 2001). But I switched to EJS when I learn about EJS.
It save me a lot of time. Most of the simulations can be created within several hours because I do not need to write code to create GUI elements.
I did not define java class in "traffic control simulation". I add all the necessary code in EJS.
You can add code in "Fixed relaton pages" if you just want to add random turn when car arrive at an interaction.
For example:
[code]
if x[],y[] and vx[] and vy[] are position and velocity vector for each car.
for(int i=0;i<n;i++){
if(car_at_interaction(i,x,y)){// define function car_at_interaction to check ith car arrive at interaction
  if(vx[i]==0){// car moving in y direction
    if(Math.random()>0.5){
      vy[i]=vx[i];// car make a left turn
    }else{
      vy[i]=-vx[i];// car make a right turn
    }
    vx[i]=0;
  }else {// car moving in x direction
    if(Math.random()>0.5){
      vx[i]=vy[i];// car make a left turn
    }else{
      vx[i]=-vy[i];// car make a right turn
    }
    vy[i]=0;
  }
}
}
[/code]