static String[] checklist = {"FOR", "AXE", "JAM", "JAB", "ZIP", "ARE", "YOU", "JUG", "JAW", "JOY"};
public static void main (String[] args)
{
int letterRange=26;
int numberRange=10;
String x;
String letters = new String(Letters(letterRange));
int numbers = Numbers(numberRange);
System.out.println(" The randomly generated License Plate is: " +letters + "-" +numbers);
}
public static char[] Letters(int lRange)
{
char[] letters = new char[3];
Random r = new Random();
boolean match = false;
boolean resultOk = false;
String result;
//Generating Random strings (character array)
for (int x=0; x<letters.length; x++)
{
letters[x] = (char)(r.nextInt(26) + 65);
}
//Logic for possibility exclusion
while (true)
{
if (match == true)
{
for (int x=0; x<letters.length; x++)
{
letters[x] = (char)(r.nextInt(26) + 65);
}
}
result = new String(letters);
for (int i = 0; i < checklist.length; i++)
{
if (result == checklist[i])
{
match = true;
break;
}
if ((i == checklist.length - 1) && (match == false))
{
resultOk = true;
break;
}
}
if (resultOk == true)
{
break;
}
}
return letters;
}
public static int Numbers(int nRange)
{
int result = 0;
int[] numbers = new int[3];
Random r = new Random();
for (int x = 0; x < numbers.length; x++)
{
numbers[x] = r.nextInt(nRange);
}
for (int i = numbers.length; i >= 1; i--)
{
result += numbers[i-1] * (10 * (numbers.length - i));
}
return result;
}
Basically I am trying to create a random license plate with three capital letters(65, ASCII code) and with three numbers. When I run the program, I get an exception for static int z=Integer.parseInt(y);
. So basically what I did was that I converted String arrays to String, and then String to int and then int to char and after that I did a while loop(saying if letters is not equal to b), then it should work.
Can you please help me? Also, am I supposed to have two methods for this? And I want to surround the license plate by a box to make it look good.