Find First Character (findfirst)
CS 162 - Spring 2008

Overview
In this assignment, you will enhance your IO program. The revised program will read in each word, search for its first letter in the puzzle, and print out the coordinates of where the first letter was found. If a word's first letter is not found in the puzzle, you will print a message.

Specifications
This program should do everything required of IO as well as the enhancements. Do not print the border of '=' in the printing function; adjust the bounds of your loops. The '=' characters should remain in the array.

After reading and printing the puzzle, read in word strings one per line. For each word, look for its first letter in the puzzle. Whenever the first letter is found, print the row and column coordinates where it was found. If the first letter is not found anywhere in the puzzle, print a message saying so. Continue reading words until end of file.

You must break the problem into several small functions where each function does one conceptual action. Have each function do one thing well.

 Input
 from
 file
 6 9
 lionsraeb
 stawnelpa
 dnawsgaad
 inergionn
 ozocatkda
 ohawktoap

 Input
 from
 user
 dog
 swan
 zebra
 quail
 horse
 frog
 
 
     Output
l i o n s r a e b 
s t a w n e l p a 
d n a w s g a a d 
i n e r g i o n n 
o z o c a t k d a 
o h a w k t o a p 

dog could start at 3,1
dog could start at 3,9
dog could start at 5,8
swan could start at 1,5
swan could start at 2,1
swan could start at 3,5
zebra could start at 5,2
quail not found
horse could start at 6,2
frog not found

Steps to Solving the Problem

Create findWords function. After reading and printing the puzzle, your program should begin finding words in the puzzle. To separate the building of the puzzle from finding the words, create a findWords function. This function takes in the puzzle array as its only parameter. Call it from main.

Read words. In findWords, write a while loop to read words from standard input. Give a short prompt for the user. Type control-d (control-z on Windows) when typing words from the keyboard to indicate there is no more input. Remember the Scanner member functions of hasNext( ) and next( ). For testing purposes, print the word inside the loop. Perhaps count how many words were read and print a total. Save, compile, and test.

Start a locationInPuzzle function. This function returns a String describing where the word is found in the puzzle. If the word is found, that information is in the returned string. If the word is not found, the returned string is empty. It takes in the puzzle and the word as its parameters. Have this function return an empty string for now.

Call that function from findWords saving the answer as a string. Depending on whether the answer is empty or not, print the answer or a message about the word not being found. Because locationInPuzzle isn't searching, no words are found. Yet.

Complete locationInPuzzle function. The locationInPuzzle function should go through the entire useful puzzle (carefully think about the bounds). At each location, it asks the searchAt function (see below) to describe whether the word is found there and adds that to its answer. locationInPuzzle has two nested for loops to visit each puzzle location.

Write simple version of searchAt function. The searchAt function takes a puzzle, a word, a row, and a column and builds a string saying word could start at row,column if it might and leaving the string empty otherwise. Don't print here. For now, just check the first character of word and build a string describing the word and location if the characters match. For example: ham could start at 1,1

Repair problems. Before submitting your final version as the findfirst assignment, check that your program uses functions extensively, has appropriate comments for each function, and is indented to match the program's control structure.

A better word list for this puzzle is: lion, bear, tiger, horse, cat, dog, swan, koala, panda, rat, and hawk. There are interesting leftovers.