Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Declare a private final List named dictionary to store the contents from Dictionary.txt. Declare and allocate a private List named list to store the list

Declare a private final List named dictionary to store the contents from Dictionary.txt.

Declare and allocate a private List named list to store the list of valid words contained in the specified String.

Declare a private String named word to store the current word being queried.

Declare and initialize a private int named count to keep track of the number of recursive calls made.

Methods

Implement the constructor for QueryResults.

Implement the following getter methods:

getCount

getDictionary

getList

getWord

Implement the readDictionary method.

At this stage you should test the readDictionary method to make sure that it is correct. Do this by adding the following code to your main method after the statement that instantiates your QueryResults object:

System.out.printf("Entry one: %s Entry two: %s ", qr.getDictionary().get(0), qr.getDictionary().get(1)); 

Once you are convinced that the readDictionary method works, work on the first line of the toString method. This will look like Dictionary has 69901 words.

Implement searchDictionary and searchDictionaryHelper

After you have finished implementing the methods you can test to make sure you are doing the recursion correctly by printing out each String inside the helper method.

System.out.println("SEARCH: " + word); 

A list of search strings for the word "there" is shown below.

SEARCH: there SEARCH: here SEARCH: ere SEARCH: her SEARCH: ther SEARCH: her SEARCH: the 

WARNING

Dont forget to remove the print statement after you have verified that the method works correctly.

Implement the toString method using the following format.

Dictionary has 69901 words Original string is "there" String size equals 5 Method called 7 times Contains: there here ere her the 

import java.io.File;

import java.io.FileNotFoundException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class QueryResults {

// class variables go here

private final List dictionary;

private List list;

private String word;

private int count;

/**

* Constructor for the QueryResults class.

* Initialize the dictionary and list objects

* @param filename name of the dictionary file

* @throws FileNotFoundException exception is thrown to the calling method if unable to open file

*/

public QueryResults(String filename) throws FileNotFoundException {

// Call the readDictionary method to assign contents to the member variable, dictionary.

// Instantiate a new ArrayList for the list variable.

dictionary = new ArrayList<>();

list = new ArrayList<>();

word = "";

count = 0;

}

/**

* Getter method for the dictionary object.

* @return {@link java.util.List} dictionary object

*/

public List getDictionary() {

return dictionary;

}

/**

* Getter method for the list object.

* @return {@link java.util.List} of words found in {@link QueryResults#searchDictionary} method.

*/

public List getList() {

return list;

}

/**

* Get number of recursive calls.

* @return the number of recursive calls used in {@code searchDictionary}.

*/

public int getCount() {

return count;

}

/**

* Getter method for the current string being queried.

* @return the word being queried

*/

public String getWord(){

return word;

}

/**

* Create a new {@link java.util.List} and then read each token from

* the file called {@code filename} and add it into the

* {@link java.util.List}.

*

* @param filename name of file

* @return A list of legal words to use for this recitation

* @throws FileNotFoundException exception is thrown to the calling method if unable to open file.

* @see Scanner#hasNext()

* @see Scanner#next()

*/

public List readDictionary(String filename) throws FileNotFoundException{

File f = New File(filename);

return null;

}

/**

* Recursively search substrings of the parameter {@code word}

* and store uniquely in the {@link java.util.List} {@code list}.

*

*

*

    *

  1. Assign {@code word} into the corresponding member variable

    *

  2. Set the member variable for count back to 0

    *

  3. Assign {@code list} to the return value for {@link QueryResults#searchDictionaryHelper(List, String)} method.

    * Pass in a new ArrayList and the word as parameters.

    *

*

* @param word the word to query.

*/

public void searchDictionary(String word) {

}

/**

* Helper method for {@code searchDictionary}.

*

* Your recursive logic goes here:

*

*

    *

  1. If the word is less than or equal to two characters, return {@code wordList}.

    *

  2. Increment the counter.

    *

  3. Add the word if it is in the dictionary but not already in the list.

    *

  4. Recursively call the method twice: Once with the first character removed

    * and once with the last character removed.

    *

* Use {@link ArrayList#contains(Object)}.

* @param wordList A List of unique legal substrings from the parameter, word

* @param word The word being queried

* @return A List of unique legal substrings from the parameter, word

* @see ArrayList#contains(Object)

*/

public List searchDictionaryHelper(List wordList, String word){

return wordList;

}

/**

* toString for you QueryResults class.

* @return String that prints information about the class

*/

@Override

public String toString() {

// Remember to double check your formatting

return "";

}

public static void main(String [] args) throws FileNotFoundException {

// Instantiate object

QueryResults qr = new QueryResults(args[0]);

// Call searchDictionary method with a word

qr.searchDictionary(args[1].toLowerCase());

// Print list of words found

// you could also type: System.out.println(qr.toString());

System.out.println(qr);

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems X Special Issue On Database And Expert Systems Applications Lncs 8220

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2013th Edition

3642412203, 978-3642412202

More Books

Students also viewed these Databases questions

Question

Select all solutions to the following inquality 2m-3>=-23

Answered: 1 week ago

Question

What is the relationship between humans and nature?

Answered: 1 week ago