Dictionary

Create a class named Dictionary has an ArrayList of strings as a property and that includes the following methods:

  • void displayAll() - displays all words stored in the dictionary
  • boolean add(String word1) - adds a word to the dictionary. If word1 already exists in the dictionary, it must not be added a second time. True is returned if word1 was successfully added, false is returned if it was not added. Words are case-sensitive so "Cat" is a different word than "cat".
  • String getRandomWord() - returns a random word from the dictionary
  • boolean find(String word1) - returns true if word1 is found in the dictionary, false otherwise
  • boolean remove(String word1) - removes word1 in the dictionary and returns true if it was found, false is returned otherwise
  • int getNumWords() - returns the number of words in the dictionary
  • boolean findAndReplace(String word1, String word2) - finds the occurrence of word1 in the dictionary and replaces it with word2. True is returned if word1 was found and replaced successfully with word2, false is returned if word1 was not found and nothing was replaced. If word2 already is found in the dictionary, do not perform the replacement. Return false in that case.
  • create a default constructor that uses Scanner to read the words found in the Handout folder's dictionary.txt file (or here) into the ArrayList property.

Write a test class named DictionaryTest that thoroughly tests all of the methods and constructor(s). The test class must be adequately annotated so its easy for the instructor to see that all the methods work correctly.

Your program must follow the class Coding Standards.

Preconditions:

    • None

You must hand in the following on separate pages stapled in this specified order:

    1. The source code for the Dictionary class.
    2. The source code for the DictionaryTest class.
    3. The screen capture of your program's output.