As promised here is the code that I manage to create, not bad for a beginner.
[code]package semaforo;

import java.lang.String;
import java.util.Random;
import java.util.Scanner;


public class Semaforo {

/**
* @param args
*/

public static void main(String[] args) {
int m = 0; // Duration of the simulation in seconds (m)
int n = 0; // Lights in the period of the second (n)
int d = 0; //With the period in which the state of the road is shown on the screen (d)
int car = 0; // car variable
char traficlight = '-'; // traffic light variable  state = open

int road = 0;  // road  variable
int simulation;    // simulation variable
int alfacar = 65;  // car showed in alphabetic letters ( código inserido posteriormente)
String history;    // string history    ( código inserido posteriormente)



Random gencar = new Random();
Scanner scan = new Scanner(System.in);

System.out.println("Introduza valor para m:"); // include the value of m
simulation  = scan.nextInt();
System.out.println("Introduza valor para n:"); // include the value of n
n  = scan.nextInt();
System.out.println("Introduza valor para d"); // include the value of d
d  = scan.nextInt();
history = new String("....");



while(m < simulation){

if(road == n){
road = 0;
traficlight = traficlight == '-' ? '|' : '-';
}
road++;


char[] vetchistory = new char[history.length()]; 
vetchistory = history.toCharArray();
for(int i = history.length()-2; i >= 0;i--){
if(traficlight == '-' || (traficlight == '|' && vetchistory[i+1] == '.')){
vetchistory[i+1] = vetchistory[i];
vetchistory[i] = '.';
}
}
System.out.println(car + ":" + m + ": " + history.toString() + traficlight);  // this part runs the cars and show them as Alpha Characters
if(car == 0 && vetchistory[0] == '.'){
vetchistory[0] = (char)alfacar;
history = String.copyValueOf(vetchistory);
if(alfacar == 90) alfacar = 65;
else alfacar++;
}else if(car == 0){
history = String.copyValueOf(vetchistory);
history = (char)alfacar + history.toString();
if(alfacar == 90) alfacar = 65;
else alfacar++;
}else{
history = String.copyValueOf(vetchistory);
history = "." + history.toString();
}
if(car == 0 || car == -1){
car = (int) Math.floor(Math.random()*d) + 1;
}
car--;
m++;
}



}

}
[/code]