Lab: Words and Separators
Objective
In this lab you will implement a couple of methods that might
be useful in the solution to the Glossary
project.
Setup
Follow these steps to set up a project for this lab.
- Create a new Eclipse project by copying ProjectTemplate.
Name the new project NextWordOrSeparator.
- Open the src folder of this project and then open
(default package). As a starting point you can use any of
the Java files. Rename it NextWordOrSeparatorTest and
delete the other files from the project.
- Follow the link to NextWordOrSeparatorTest.java,
select all the code on that page and copy it to the clipboard;
then open the NextWordOrSeparatorTest.java file in
Eclipse and paste the code to replace the file contents. Save your
file.
Method
- First carefully look through the NextWordOrSeparatorTest.java
file and the main method in particular. Make sure you understand
what the method does. What is the definition of "separator"
characters used in the program?
- Complete the given class by pasting the bodies of the generateElements
and nextWordOrSeparator static methods you wrote for the
homework into the NextWordOrSeparatorTest.java file.
- Run the program and thoroughly test your implementations
with a variety of different inputs involving different characters,
including letters, digits, white space characters, and various
punctuation characters.
Additional Activities
- Create a JUnit test fixture and provide test cases for the
static methods you implemented.
- Modify the definition of "separator" characters to better
match your intuition of what a word and a separator
string should be. Test your modified implementation.