Hi guys! This is a pretty basic problem: I don’t fully understand how to use loops.
I want to get comfortable with using arrays and other elementary stuff so I came up with the idea of creating some kind of licence plate generator.
int[] numbers = new int[99];
char[] chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W' };
String[] plates = new String[10];
String a = "B-" +
  chars[int(random(chars.length)) ] + 
  numbers[int (random(numbers.length) )] + 
  chars[int(random(chars.length)) ] +
  chars[int(random(chars.length))] +
  numbers[int (random(numbers.length) )] ;
void setup() {
  size(400, 400, P2D);
  frameRate(1);
  for (int i=1; i<numbers.length; i++) {
    numbers[i]= (int)i;
  }
}
void draw() {
  background(155);
  textSize(58);
  textAlign(LEFT);
  text(a, 30, height/2);
  for (int i=0; i<plates.length; i++) {
    plates[i]= a;
  }
  if (plates[9]!=null) {
    println(plates[0]);
    println(plates[1]);
    println(plates[2]);
    println(plates[3]);
    println(plates[4]);
    println(plates[5]);
    println(plates[6]);
    println(plates[7]);
    println(plates[8]);
    println(plates[9]);
  }
}
It’s supposed to take entities of the numbers and char array to create a plate and save it in a dedicated array (plates). I (think I) understand the problem, but can’t come up with a solution.
Right now it generates a code and saves it to the array, but for every position.
Can anybody please give me a hint, like what buzzword should I search for or explain it to me right away?
Hope the formatting is OK and I’ll appreciate any help =)
I came up with a solution:
int[] numbers = new int[99];
char[] chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'R', 'S', 'T', 'U', 'V', 'W' };
String[] plates = new String[100];
String a;
int i;
void setup() {
  size(400, 400, P2D);
  frameRate(999);
  for (int i=1; i<numbers.length; i++) {
    numbers[i]= (int)i;
  }
}
void draw() {
  a= "B-" +
    chars[int(random(chars.length) )  ] + 
    numbers[int (random(numbers.length) )  ] + 
    chars[int(random(chars.length) )  ] +
    chars[int(random(chars.length) )  ] +
    numbers[int (random(numbers.length) )  ] ;
  background(155);
  textSize(58);
  textAlign(LEFT);
  text(a, 30, height/2);
  plates[i] = this.a;
  i=i+1;
  if (i>=100) {
    noLoop();
    printArray(plates);
  }
}
            

