Background:
This lab will provide you with another opportunity to work with classes
and objects as well as a new class: the ArrayList. Once you're done, you
will use the Intro-CS Assignment Dropoff form to hand in your finished program.
What You'll Need
Download the lab4.zip file from the 15-111 course web site. Unzip
the file and you should see the following:
- words.txt (a small file to test your program initially
- dictionary.txt (a very large file of words)
Assignment
You are to implement a set of classes that stores a searchable list of words. By the end of the course, I hope to have you implementing a word game like Scrabble or TextTwist. A sample execution of the current assignment will be shown in lecture on Thursday. The functional specifications are as follows:
- The user must be prompted for the name of a file of words to read in, as well as the maximum length of the words to be stored (note: this is a maximum word length, not a maximum number of words.
- The program will build a list of words less than or equal to the specified length. Once the word list is created, the user should be prompted for a string to search for and should output all the words that are anagrams for the entered string if any. This should continue until the user enters a specific string of your choosing to signal termination.
- Each Word object will contain two instance variables: the initial word and the word with all its letters arranged in sorted order. You will need a private method to sort the letters of the initial word (using a StringBuffer as Strings are immutable). The Word object should also support an overloaded equals method that takes a String as a parameter and returns true if the Word is an anagram for the String.
- The WordList class should contain a default constructor, a method to add a word to the current list, a method to print all anagrams of a specified string, and, of course, a toString().
- Somewhere you will need to have a constructor (either the WordList class or some other class) that takes a BufferedReader parameter (the external file) and an int parameter (the max length of words to be considered) and then uses that file to build the list of words that are less than or equal in length to the specified max.
- Somewhere also you will need to support a method to generate and print all the anagrams until the user of your program enters the termination string.
Think about your class design before coding your solution. Start with the Word class and test it out with respect to checking anagrams before going on to the WordList class. Remember that ArrayLists store generic Objects and so, when you access an item from an ArrayList, it will have to be downcast to a Word.
Handing in your Solution
Your solution should be in the form of a .zip file. When we grade your solution
we will unzip the folder and execute the Java files.
Use the Intro Programming
dropoff form to submit your zip file.