Java Reference
In-Depth Information
Your application should recognize invalid conversions. For example, the question
"How many feet are in 5 kilograms?"
is not meaningful because "feet" is a unit of length, whereas "kilograms" is a unit of mass.
Special Section: Challenging String-Manipulation Projects
14.24 (Project: A Spelling Checker) Many popular word-processing software packages have built-
in spell checkers. In this project, you're asked to develop your own spell-checker utility. We make
suggestions to help get you started. You should then consider adding more capabilities. Use a com-
puterized dictionary (if you have access to one) as a source of words.
Why do we type so many words with incorrect spellings? In some cases, it's because we simply
do not know the correct spelling, so we make a best guess. In some cases, it's because we transpose
two letters (e.g., “defualt” instead of “default”). Sometimes we double-type a letter accidentally
(e.g., “hanndy” instead of “handy”). Sometimes we type a nearby key instead of the one we
intended (e.g., “biryhday” instead of “birthday”), and so on.
Design and implement a spell-checker application in Java. Your application should maintain
an array wordList of strings. Enable the user to enter these strings. [ Note: In Chapter 15, we intro-
duce file processing. With this capability, you can obtain the words for the spell checker from a
computerized dictionary stored in a file.]
Your application should ask a user to enter a word. The application should then look up that
word in the wordList array. If the word is in the array, your application should print " Word is
spelled correctly . " If the word is not in the array, your application should print " Word is not
spelled correctly . " Then your application should try to locate other words in wordList that
might be the word the user intended to type. For example, you can try all possible single transposi-
tions of adjacent letters to discover that the word “default” is a direct match to a word in wordList .
Of course, this implies that your application will check all other single transpositions, such as
“edfault,” “dfeault,” “deafult,” “defalut” and “defautl.” When you find a new word that matches
one in wordList , print it in a message, such as
Did you mean "default"?
Implement other tests, such as replacing each double letter with a single letter, and any other
tests you can develop to improve the value of your spell checker.
14.25 (Project: A Crossword Puzzle Generator) Most people have worked a crossword puzzle, but
few have ever attempted to generate one. Generating a crossword puzzle is suggested here as a string-
manipulation project requiring substantial sophistication and effort.
There are many issues the programmer must resolve to get even the simplest crossword-puz-
zle-generator application working. For example, how do you represent the grid of a crossword puz-
zle inside the computer? Should you use a series of strings or two-dimensional arrays?
The programmer needs a source of words (i.e., a computerized dictionary) that can be directly
referenced by the application. In what form should these words be stored to facilitate the complex
manipulations required by the application?
If you're really ambitious, you'll want to generate the clues portion of the puzzle, in which the
brief hints for each across word and each down word are printed. Merely printing a version of the
blank puzzle itself is not a simple problem.
Making a Difference
14.26 (Cooking with Healthier Ingredients) Obesity in America is increasing at an alarming rate.
Check the map from the Centers for Disease Control and Prevention (CDC) at www.cdc.gov/
nccdphp/dnpa/Obesity/trend/maps/index.htm , which shows obesity trends in the United States
 
Search WWH ::




Custom Search