So I am making a program that is supposed to generate a random crossword puzzle. I have a method reads in a txt file that has a list of around 3000 words, stores it into an array list and returns the array list. I have a driver method which asks the user for the amount of rows and columns they want the crossword puzzle to be and from there it is supposed to generate a random puzzle. I'm using a 2d array to construct the entire puzzle but I can't figure out how to add words into the puzzle. This is what I have so far for the method that is supposed to fill in the crossword (the randomNumber method is just a method that returns a random index that is used to access a random word from the list)
public static void buildCrossword(ArrayList<String> words, int rows, int columns)
{
String[][] board = new String[rows][columns];
//Picks a random number from the arrayList using a random index from the randomNumber method
int randomNumber = randomNumber();
String randomWord = words.get(randomNumber);
//we remove it right after it is selected to ensure that it doesn't get used again in the puzzle
words.remove(randomNumber);
char[] temp = randomWord.toCharArray();
char[][] word = new char[temp.length][temp.length];
word[0] = temp;
System.out.println("*----".repeat(rows) + "*");
for(int i = 0; i < columns; i++)
{
System.out.println("| ".repeat(rows) + "|");
System.out.println(word[0][i]);
System.out.println("*----" .repeat(rows) + "*");
}
}
As you know own a crossword there are also filled in unused squares and I need to use an "*" to represent the unused squares. Any help at all would be appreciated.