Simple Recursion Program
-
Read a large amount of data from a file into an
ArrayList
-
Write a program that implements a recursive search
-
Create a project called L6.
-
Download the QueryResults-starter.jar and import the
Java
archive intoEclipse
.
Instructions for how to do this can be found here.
Your project directory should now look like this:
L6/ ├── resources │ └── Dictionary.txt └── src └── QueryResults.java
-
Configure your Runtime Configurations to have the following arguments:
resources/Dictionary.txt there
In the spirit of incremental development, we suggest you design your program using the following model:
Variables
-
Declare a private final
List<String>
named dictionary to store the contents from Dictionary.txt. -
Declare and allocate a private
List<String>
named list to store the list of valid words contained in the specifiedString
. -
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\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
.
-
Implement
searchDictionary
andsearchDictionaryHelper
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. |
-
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. |