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

Java Your assignment is to write a dictionary program that uses a tree structure

ID: 3771317 • Letter: J

Question

Java

Your assignment is to write a dictionary program that uses a tree structure.

See project 8 on page 669 and figure 24-8 on page 689 in your text for some additional hints/ideas.

The requirements for the program are:

It must be in a single java file called “NameDictionary.java” where Name is your last name.

It must first display a message stating: “Tree dictionary program created by Your Name”.

Next have the user provide the name of a text (*.txt) file with a dictionary of English words in it.

Next it is to read in the dictionary of words from the input text file. Make certain to have this in a try block in case a bad file name was input. If the program cannot open the file for input, it must prompt the user again for a file name and continue to do this until a good name is provided. The file is to have one word on each line and may be of any length.

You must reject (ignore and display an error message) any words being input that have non-letters in them, that is,something like all13 or f@t. So no hyphenated words. But your program is to continue running after displaying the error messages as if nothing was wrong except that the rejected words will not be placed in the dictionary.

All acceptable words input should be converted so that all letters are in lower case.

The program is to then create a tree structure from the input words.

I would suggest using a linked list with up to 26 branches at each node for this, but you may use some other treestructure if you wish.

The program will then loop asking the user to input a word which the program will check to see if it is in the dictionary or not using the created tree. If the word is in the dictionary, the program will display the message: “xxxxx is in the dictionary” where xxxxx is the input word. If the word is not found in the dictionary, the program is to display the message: “xxxxx is not in the dictionary”. In either event, the program is to then ask for another word to be input and check if it is in the dictionary or not. This will continue until an empty string is input which will terminate the program.

Email the “.java” file, a sample output file, and the class file to me in a single e-mail message with three attachments (do not put any of the files in the body of the e-mail) by noon December 16, 2015 (that is one day after the in class portion of the final).

You do not need to e-mail a dictionary file to me as I will provide that.

Note, you must make certain that your program can handle words like the following in the dictionary: “a”, “an”, “ant”, “another” etc. and successfully find them if they are input. You may want to use a flag indicating that a node may be the end of a word, but that additional nodes may follow because another word (or words) has the same start but more letters.I have included a sample dictionary file out on D2L along with these directions, but that will not in be the dictionary I useto test your program.

Note that duplicate dictionary items should be taken care of automatically as they should map in the same way to the tree.

Explanation / Answer

public static void main(String []args) throws IOException{
BufferedReader in = null;
Scanner input = new Scanner(System.in);
String str;
boolean notfound = false;
char again = 'a';

try{
do{
notfound = false;
System.out.println("Enter word :");
str = input.next();
File f = new File("/Folder/demo1.txt");
in = new BufferedReader(new FileReader(f));
String s;

while((s = in.readLine()) != null){

int x = s.indexOf(str);
// System.out.println("Index of dash:" + s.indexOf("-"));
// System.out.println("Index of Hello:" + x);

if(x != -1 && x<s.indexOf("-")){

String sub = s.substring(0,s.indexOf("-"));
System.out.println("Sub:" + sub);
System.out.println("Str:" + str);
if(sub.trim().equals(str.trim())){
System.out.println("Success:" +sub);
notfound = true;
break;


}

else{
System.out.println("Word is not present") ;
notfound = false;
break;
}
}

}
if(!notfound){
System.out.println("Try another word?(y/n):");
again = input.next().trim().charAt(0);
again = Character.toLowerCase(again);
}
}
while(notfound || again == 'y');
System.out.println("terminated!");
}
finally{
if(in != null){
in.close();
}

}
}
}

Thank you

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote