Project Week 1: Auto Complete
This is the first week of a multi-week project. The project will allow you to integrate learning from throughout the freshman software development and data structures sequence. You will develop several data structures and analyze the advantages and disadvantages of each. The project will result in a user interface showing the results.
Your program must have a user interface similar to the one shown here.
Users may type characters into search box. The list of matches below must be immediately after a letter is typed or deleted. In addition, the time required to find an exact match and all matches with the same prefix should be displayed in appropriate text boxes for both the sorted list and unsorted list data structures.
You must create the
AutoCompleter interface with the following methods:
boolean add(String word)— returns
wordis added to the object. If
nullor an empty string, an
int size()— returns the number of items contained by the object.
boolean exactMatch(String target)— returns
targetis found in the object. If
String allMatches(String prefix)— returns an array of all the strings in the object that begin with the
prefixis an empty string, an array of all the strings in the object are returned. If
static String format(long nanoseconds)— returns a human-friendly string representing the number of
nanoseconds. The format of the string must be consistent with the examples below. Select the first line where the first number is at least
1. Note: this method is declared
staticwhich means that it should be implemented in the interface.
- 2 day(s) 5 hour(s) 32 minute(s)
- 14 hour(s) 22 minute(s) 8 second(s)
- 42 minute(s) 55.3 second(s)
- 18.8 second(s)
- 998.8 millisecond(s)
- 318.8 microsecond(s)
- 7 nanosecond(s)
Unsorted Collection Implementation
AutoCompleter interface using an unordered collection. Your class
must have one private attribute:
private final Collection<String> items that is
assigned via a one-argument constructor. Note: the constructor should remove any
strings in the collection passed to the constructor.
Sorted List Implementation
AutoCompleter interface using a sorted list. Your class
must have at least the following private attribute:
private final List<String> items that is assigned via a one-argument
constructor. Recommendation: add the items in whatever order they are
given, then ensure that
items is sorted before searching for matches.
Collections.binarySearch() in your implementations of
If any problems are encountered with reading the input file with the word list, the program should display a useful error message to the console and terminate gracefully. The program should not crash or display any exceptions.
Just For Fun
Ambitious students may wish to:
allNonPrefixMatches(String substring)to the interface. This method returns all strings that contain the substring passed as an argument.
This laboratory assignment, developed by Dr. Chris Taylor.