Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a program name anagram.java that prompt the user for a user input file, re

ID: 3628467 • Letter: W

Question

write a program name anagram.java that prompt the user for a user input file, reads the input words and computes anagram of words. An anagram of a word is a permutation of the letters in that word; for example, “stop” is an anagram of “tops”.

As indicated, the input to the program is a list of words from a user input file. The output is a list containing the same words, but with anagrams displayed on the same line both on the screen and the output file. The output file must be named output.txt.

The input file, may look like the following: You must prompt the user for the name of the input file.

Pans naps

Pots

opt this that

Sit

it’s

snap

and so on.

Here are some requirements for the program:

1. When determining if two words are anagrams, the program must treat upper and lower case letters as equivalent (thus “Pans” and “snap” are anagrams) and ignore punctuation marks (“it’s” and “Sit” are anagrams). However, the program must display words with their original capitalization and punctuation – as shown above.

2. The “word” is assumed to be any series of nonblank characters; words may be separated by any number of white-space characters. Any number of words may appear on a line,
including none. You may assume that no word is more than 12 characters long. And maximum number of words would be 50.

3. The program must work even if the input file is empty. If this is the case print a message saying that “the input file is empty” and then terminate the program.

4. The program must test the number of characters per word. If a word consist of more than 12 characters, the program should ignore that word and continue. That word would also be ignored in the total number of words of 50.

5. The program must also test the number of words. If there are more than 50 words, print a message saying that “there are more than 50 words in the input file” and then terminate the program

Explanation / Answer

Well, I cannot write the whole program for you, but it'd be nice if you would mention where specifically you needed help. I'll assume you know file i/o, and just offer some assistance with the anagram part. It'd be helpful to read the the strings in the file into a string variable: String input; input = fileInput.nextString(); (I assume you know what class to scan in the word from the input file) This would be done inside a loop that checks for the end of the file. After reading it in as a string, the code for anagrammin' the string would be best done in a for loop: String output=""; for(int i=input.length; i>=0;i--){ output+=input.substring(i,i); } the string "output" will then have a perfect anagram. you could instantiate it as an array to contain all the outputs your program needs. check the string API for more help, as there is a method there that will remove white space. Hope this starts you out.