Select Page

University of Wisconsin Madison Public Static ArrayList Java Project Questions

Question Description

I’m working on a Java project and need support to help me study.

Use this code for part 2 of the assignment(I already did part 1).

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
import java.io.InputStreamReader;
import java.io.IOException;

public class WordSearch {
public static void main(String[] args) {

testReadDictionary();
testReadWordSearch();

}
/**
* Opens and reads a dictionary file returning a list of words.
* Example:
* dog
* cat
* turtle
* elephant
*
* If there is an error reading the file, such as the file cannot be found,
* then the following message is shown:
* Error: Unable to read file <dictionaryFilename>
* with <dictionaryFilename> replaced with the parameter value.
*
* @param dictionaryFilename The dictionary file to read.
* @return An ArrayList of words.
*/
public static ArrayList<String> readDictionary(String dictionaryFilename) {
//FILL IN BODY
ArrayList<String> animals = new ArrayList<>();

FileInputStream filestream;
try {
filestream = new FileInputStream(dictionaryFilename);
BufferedReader br = new BufferedReader(new InputStreamReader(filestream));

String str = br.readLine();

while (str != null) {

animals.add(str);

str = br.readLine();
}

br.close();

} catch (FileNotFoundException e) {
System.out.println(” Unable to read file ” + dictionaryFilename);

} catch (IOException e) {

e.printStackTrace();
}

return animals;

}

/**
* Opens and reads a wordSearchFileName file returning a block of characters.
* Example:
* jwufyhsinf
* agzucneqpo
* majeurnfyt
*
* If there is an error reading the file, such as the file cannot be found,
* then the following message is shown:
* Error: Unable to read file <wordSearchFileName>
* with <wordSearchFileName> replaced with the parameter value.
*
* @param wordSearchFileName The dictionary file to read.
* @return A 2d-array of characters representing the block of letters.
*/
public static char[][] readWordSearch(String wordSearchFileName) {

ArrayList<String> words = new ArrayList<>();

FileInputStream filestream;
try {
filestream = new FileInputStream(wordSearchFileName);
BufferedReader br = new BufferedReader(new InputStreamReader(filestream));

String str = br.readLine();

while (str != null) {

words.add(str);

str = br.readLine();
}

br.close();

} catch (FileNotFoundException e) {
System.out.println(” Unable to read file ” + wordSearchFileName);

} catch (IOException e) {

e.printStackTrace();
}

char[][] charWords = new char[words.size()][];

for (int i = 0; i < words.size(); i++) {

charWords[i] = words.get(i).toCharArray();
}

return charWords;
}

public static void testReadDictionary() {
//ADD TEST CASES
ArrayList dictionaryWords;

System.out.println(“Positive Test Case for Dictionary Serach”);
String dictionaryFilePath = “C:dictionary.txt”;
dictionaryWords = readDictionary(dictionaryFilePath);
System.out.println(“Number of words found : “+dictionaryWords.size());
System.out.println(“They are : “+dictionaryWords.toString());

System.out.println(“nNegative Test Case for Dictionary Serach”);
dictionaryFilePath = “dictionaryDummy.txt”;
dictionaryWords = readDictionary(dictionaryFilePath);
}

public static void testReadWordSearch() {
//ADD TEST CASES
char[][] wordsList;

System.out.println(“nnPositive Test Case for Word Serach”);
String wordFilePath = “C:wordsearch.txt”;
wordsList = readWordSearch(wordFilePath);
System.out.println(“Number of words found : “+wordsList.length);

System.out.println(“nNegative Test Case for Word Serach”);
wordFilePath = “C:wordsearchDummy.txt”;
wordsList = readWordSearch(wordFilePath);
}

/**
* Looks horizontally for the word in the word search, starting at
* the given position. If the given position matches the first
* character of word, look for the rest of the word characters
* in the indexes to the right and left
*
* @param word The word to look for.
* @param wordSearch The grid of characters to search through
* @param i The row to start searching at
* @param j The column to start searching at
* @return true if the word was found, false if not.
*/
public static boolean searchHorizontal(String word, char[][] wordSearch, int i, int j) {
//TODO: Implement

return false;
}

/**
* Looks vertically for the word in the word search, starting at
* the given position. If the given position matches the first character of
* word, look for the rest of the word characters in the indexes above and below
*
* @param word The word to look for.
* @param wordSearch The grid of characters to search through
* @param i The row to start searching at
* @param j The column to start searching at
* @return true if the word was found, false if not.
*/
public static boolean searchVertical(String word, char[][] wordSearch, int i, int j) {
//TODO: Implement
return false;
}

/**
* Looks diagonally (up-left, up-right, down-left and down-right) for the word in the
* word search, starting at the given position. If the given position matches
* the first character of the word, look for the rest of the word
* characters in the four diagonal directions.
*
* @param word The word to look for.
* @param wordSearch The grid of characters to search through
* @param i The row to start searching at
* @param j The column to start searching at
* @return true if the word was found, false if not.
*/
public static boolean searchDiagonal(String word, char[][] wordSearch, int i, int j) {
//TODO: Implement
return false;
}

public static void testSearchHorizontal() {
//ADD TEST CASES
}

public static void testSearchVertical() {
//ADD TEST CASES
}

public static void testSearchDiagonal() {
//ADD TEST CASES
}
}

Use this code below for part 3(I already did part 1).

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class WordSearch {

public static void main(String[] args) {
Scanner userInput = new Scanner(System.in);
System.out.println(“Enter the wordSearch file name”);
String wordSearchFile = userInput.next();

//Use scanner to read in the word search file name

}

/**
* Given the name of a dictionary file, and the name of the word search file, this
* will solve the word search by finding all of the words listed in the dictionary file.
*
* Duplicates should not be returned.
*
* @param dictionaryName The dictionary file to read.
* @param wordsearchName The file containing the word search.
* @return An ArrayList of words found.
*/
public static ArrayList<String> searchForWords(String dictionaryFileName, String wordSearchFileName){

//IMPLEMENT

return null;
}

/** Given the name of a list, print the words in the list onto an output file
* named “wordsfound.txt”
*
* @param foundWords an ArrayList of words found
*/
public static void printWordsFound(ArrayList<String> foundWords){

//IMPLEMENT

}

public static void testSearchForWords(String wordSearchFileName, String answersFileName){

//IMPLEMENT

}

public static void testPrintWordsFound(String wordsFoundFileName){

//IMPLEMENT

}
}

"Place your order now for a similar assignment and have exceptional work written by our team of experts, guaranteeing you "A" results."

Order Solution Now