complete 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 {
/**
* Picks the first unguessed word to show.
* Updates the guessed array indicating the selected word is
shown.
*
* @param wordSet The set of words.
* @param guessed Whether a word has been guessed.
* @return The word to show or null if all have been guessed.
*/
public static String
pickWordToShow(ArrayList<String> wordSet, boolean []guessed)
{
return null; //TODO
}
-----------------------------------------------------
/**
* Some test cases for the pickWordToShow method.
*/
private static void testPickWordToShow() {
boolean error = false;
{ //
ArrayList<String> wordSet = new ArrayList<>();
wordSet.add("ago");
wordSet.add("now");
wordSet.add("own");
wordSet.add("wagon");
boolean []guessed = {true,false,true,false};
String expected = "now";
String actual = WordDetective.pickWordToShow(wordSet,
guessed);
if (!actual.equals(expected) || !guessed[1]) {
error = true;
System.out.println("testPickWordToShow 1: actual: " + actual + "
expected: " + expected);
}
}
//suggest adding additional test cases.
if ( error) {
System.out.println("testPickWordToShow failed.");
} else {
System.out.println("testPickWordToShow passed.");
}
}
SOURCE CODE 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 {
/**
* Picks the first unguessed word to show.
* Updates the guessed array indicating the selected word is shown.
*
* @param wordSet The set of words.
* @param guessed Whether a word has been guessed.
* @return The word to show or null if all have been guessed.
*/
public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed)
{
for(int i=0;i<guessed.length;i++)
{
if(guessed[i]==false)
{
guessed[i]=true;
return wordSet.get(i);
}
}
return null;
}
//-----------------------------------------------------
/**
* Some test cases for the pickWordToShow method.
*/
private static void testPickWordToShow() {
boolean error = false;
{ //
ArrayList<String> wordSet = new ArrayList<>();
wordSet.add("ago");
wordSet.add("now");
wordSet.add("own");
wordSet.add("wagon");
boolean []guessed = {true,false,true,false};
String expected = "now";
String actual = WordDetective.pickWordToShow(wordSet, guessed);
if (!actual.equals(expected) || !guessed[1]) {
error = true;
System.out.println("testPickWordToShow 1: actual: " + actual + " expected: " + expected);
}
}
//suggest adding additional test cases.
if ( error) {
System.out.println("testPickWordToShow failed.");
} else {
System.out.println("testPickWordToShow passed.");
}
}
}
OUTPUT:

complete 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...
complete 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 { /** * Picks the first unguessed word to show. * Updates the guessed array indicating the selected word is shown. * * @param wordSet The set of words. * @param guessed Whether a word has been guessed. * @return The word to show or null if all have been guessed. */ public static String pickWordToShow(ArrayList<String> wordSet, boolean []guessed) { return null; //TODO...
Complete 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 { /** * This returns a string containing the char ch, count times. * For example calling with 'a', 5 would return: * "aaaaa" * * @param ch The character to repeat. * @param count The number of the character. * @return A string with count number of ch. */ public static String charToString(char ch, int count) { return null; //TODO }
complete 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 { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...
JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet { /** * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList * containing all the indexes of Strings in arr that match String s. For this method, two Strings, * p and q, match when p.equals(q) returns true or if both of the compared references are null. * * @param s The string...
package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput; /** Write a program to roll a set of dice. Generate a random number between 1 and 6 for each dice to be rolled, and save the values in an ArrayList. Display the total of all the dice rolled. In some games, rolling the same number on all dice has a special meaning. In your program, check if all dice have the same value,...
Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This class is used by: * 1. FindSpacing.java * 2. FindSpacingDriver.java * 3. WordGame.java * 4. WordGameDriver.java */ public class WordGameHelperClass { /* * Returns true if an only the string s * is equal to one of the strings in dict. * Assumes dict is in alphabetical order. */ public static boolean inDictionary(String [] dict, String s) { // TODO Implement using binary search...
how would i use test.add because i would like to use add import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Scanner; public class checkFruit { private List<String> tests; public List<String> getFruit(String fruits) { tests = new ArrayList<String>(Arrays.asList(fruits.split(","))); for (String test : tests) { System.out.println(test); tests.add()//how would i use add here } return tests; } public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter file name: "); File file = new File(in.nextLine()); try { checkFruit...
import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private ArrayList<String> words; private HashSet<String> foundWords = new HashSet<String>(); public FindWordInMaze(char[][] grid) { this.grid = grid; this.words = new ArrayList<>(); // add dictionary words words.add("START"); words.add("NOTE"); words.add("SAND"); words.add("STONED"); Collections.sort(words); } public void findWords() { for(int i=0; i<grid.length; i++) { for(int j=0; j<grid[i].length; j++) { findWordsFromLocation(i, j); } } for(String w: foundWords) { System.out.println(w); } } private boolean isValidIndex(int i, int j, boolean visited[][]) { return...
import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class FindWordInMaze { private char grid[][]; private ArrayList<String> words; private HashSet<String> foundWords = new HashSet<String>(); public FindWordInMaze(char[][] grid) { this.grid = grid; this.words = new ArrayList<>(); // add dictionary words words.add("START"); words.add("NOTE"); words.add("SAND"); words.add("STONED"); Collections.sort(words); } public void findWords() { for(int i=0; i<grid.length; i++) { for(int j=0; j<grid[i].length; j++) { findWordsFromLocation(i, j); } } for(String w: foundWords) { System.out.println(w); } } private boolean isValidIndex(int i, int j, boolean...
import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...