Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Lab 4: Anagrams (CSE 15L, October 19, 2011)
 
Definition: An anagram of a word is a new word or phrase that contains all the letters of the original word, 
using each original letter exactly once.  New spaces and punctuation are allowed in the anagram.
 
This lab uses two Java files.  The main method is in TestAnagram.java.  This calls 
LetterCount.java to generate a list of anagrams from a vocabulary list (given by the user) and a 
given root word.  In addition to the root word, the user must input an inquiry phrase.  The inquiry phrase is 
checked to see whether it is in the list or not.
 
Program Specification:  The program takes three arguments, which are the input file, root word, and 
inquiry phrase. The program generates internally a list of phrases that are combinations of vocabulary 
words connected by single spaces.  Each phrase is an anagram of the root word ignoring whitespace 
and non-letter characters.  For example, “dirty room!” is an anagram of “dormitory” because “dirty” 
and “room!” are in the vocabulary file vocabulary.txt.  A generated phrase is not limited to be a 
combination of two tokens; it could be “I rent gas” for example.  However, each token in a phrase has to 
be in the vocabulary.  Also, each token must be used in order: you can generate an anagram with token 
number i and token number j only if i <= j.  The program is not case-sensitive. If the inquiry phrase is in the 
generated list, then the program returns "Result: found". Otherwise, it returns "Result: not found".
 
Examples (User input is in blue, program output is in red)
Example 1:
java TestAnagram vocabulary.txt ‘dormitory’ ‘dirty room!’
The root word is: dormitory
The program is looking for: dirty room!
Result: found
Explanation: “dirty” and “room!” are in the dictionary and “dirty room!” is an anagram 
of “dormitory”. Make sure that you surround the words in the command line with single quotes.
 
Example 2:
$java TestAnagram vocabulary.txt ‘comfortable’ ‘comfort able’
The root word is: comfortable
The program is looking for: comfort able
Result: not found
Explanation: “comfort able” is an anagram of “comfortable” but neither “comfort” nor “able” is in the 
vocabulary.
 
Example 3:
$java TestAnagram vocabulary.txt ‘angriest’ ‘sir stare’
The root word is: angriest
The program is looking for: sir stare
Result: not found
Explanation: “sir” and “stare” are in the dictionary but they are not an anagram of “angriest”.
 
Example 4:
$java TestAnagram vocabulary.txt ‘angriest’ ‘agent sir’
The root word is: angriest
The program is looking for: agent sir
Result: found
 
Example 5:
$java TestAnagram vocabulary.txt ‘pizza’ ‘a zip’
The root word is: pizza
The program is looking for: a zip
Result: not found
 
Things to remember
● See the notes and report grading guidelines at http://cseweb.ucsd.edu/~elkan/15L/
● Strictly adhere to the submission guidelines for notes and reports, which are the same as 
previous labs.
● Try your own test cases in addition to the ones above.
● In the notes, write down your hypotheses explicitly.  
● Include everything you try, whether it succeeds or fails. Do not skip steps.