Complate this in java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class WordDetective {
/**
* Reorders the letters in word.
*
* Algorithm:
* Copy the word into an array of characters.
* Repeat 4 times:
* Randomly select 2 indexes in the word array using
* nextInt( word length) of the randGen parameter.
* Swap the letters at the selected indexes in the word array.
* Create a string from the array of characters.
*
* @param word The letters to be reordered.
* @param randGen A random number generator.
* @return The letters that have been randomly ordered.
*/
public static String reorderLetters(String word, Random randGen)
{
return null; //TODO
}
Given below is the code for the question. Please do rate the answer if it helped. Thank you.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class WordDetective {
/**
* Reorders the letters in word.
*
* Algorithm:
* Copy the word into an array of characters.
* Repeat 4 times:
* Randomly select 2 indexes in the word array
using
* nextInt( word length) of the randGen
parameter.
* Swap the letters at the selected indexes in the word
array.
* Create a string from the array of characters.
*
* @param word The letters to be reordered.
* @param randGen A random number generator.
* @return The letters that have been randomly
ordered.
*/
public static String reorderLetters(String word,
Random randGen) {
char[] arr =
word.toCharArray();
int idx1, idx2;
char temp;
for(int i = 1; i <= 4;
i++){
idx1 =
randGen.nextInt(word.length());
idx2 =
randGen.nextInt(word.length());
temp =
arr[idx1];
arr[idx1] =
arr[idx2];
arr[idx2] =
temp;
}
return new String(arr);
}
}
Complate this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class...