Class NeedlesHaystackTest


  • public class NeedlesHaystackTest
    extends Object
    NeedlesHaystackTest is a driver for the Google writing test sample "findNeedles()" method.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static boolean checkEntry​(int[] validEntries, int valueToCheck)
      Verifies that the string entered at console is an integer between 1 and 5.
      static void findNeedles​(String haystack, String[] needles)
      Finds and counts the number of each specified word (needle) (if found) that exist in the specified file (haystack).
      static void main​(String[] args)
      Launches program and prompts user for three pieces of variable input: the number of words (needles) in total that user wants to find; the specific words; and the name of the local text file (haystack) to search through.
    • Method Detail

      • checkEntry

        static boolean checkEntry​(int[] validEntries,
                                  int valueToCheck)
        Verifies that the string entered at console is an integer between 1 and 5.
        Parameters:
        validEntries - Hard-coded array of allowable entries.
        valueToCheck - String entered at console.
      • findNeedles

        public static void findNeedles​(String haystack,
                                       String[] needles)
        Finds and counts the number of each specified word (needle) (if found) that exist in the specified file (haystack). Haystack is a plaintext file stored locally. Needles are up to 5 words entered at prompts on the command line.
        Parameters:
        haystack - String object comprising the plaintext from text file.
        needles - An array containing five String objects.
        See Also:
        java.lang.String