More Recursion

Objectives
  1. Read a large amount of data from a file into an ArrayList

  2. Write a program that implements a recursive search

Getting started
  1. Create a project called L7.

  2. Download the QueryResults-starter.jar and import the Java archive into Eclipse.
    Instructions for how to do this can be found here.

Your project directory should now look like this:

 L7/
 ├── resources
 │   └── Dictionary.txt
 └── src
     └── QueryResults.java
  1. Configure your Runtime Configurations to have the following arguments:

resources/Dictionary.txt there
Implementation and Testing

In the spirit of incremental development, we suggest you design your program using the following model:

Variables

  1. Declare a private final List<String> named dictionary to store the contents from Dictionary.txt.

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

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

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

Methods

  1. Implement the constructor for QueryResults.

  2. Implement the following getter methods:

    • getCount

    • getDictionary

    • getList

    • getWord

  3. 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\nEntry two: %s\n", 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.

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
Don’t forget to remove the print statement after you have verified that the method works correctly.
  1. 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
Tip
Make sure to match spelling and punctuation exactly.

Important
Check your work off with the TA or the helper before leaving recitation.