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

Java Program Help I need some help with this program. A company is in need of a

ID: 3559344 • Letter: J

Question

Java Program Help

I need some help with this program.

A company is in need of a useful program that performs a frequency count for words read from a
text file. The program lists all words in alphabetical order, together with their frequency. The
program also allows clients to search for a word and its frequency.
Project Tasks:


1. Create a program that will read a file and store the words in the file in a binary search
tree. Each node in the tree should store a word and its frequency, i.e., how many times it
appears in the document. Your submission shall include a class, named DocumentIndex
with methods for loading a file, displaying all words in the file in alphabetical order
together with their frequencies, and (2) finding a single word, which results in the display
of the word with its frequency. The submission shall design classes using proper
encapsulation of data for each class.

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class DocumentIndex {

   static BinaryTree bTree=new BinaryTree();

   public static void main(String[] args) {
       String name;
       Scanner scan=new Scanner(System.in);
       System.out.println("Loading data into binary tree");
       loadFileDataInToTree();
       System.out.println("Names Loaded in to binary tree");
      
       System.out.println("Enter the name to search");
       name=scan.nextLine();
       bTree.lookup(name);
      
       System.out.println("Displaying names according to dictionary");
       bTree.printTree();
      
   }

   public static void loadFileDataInToTree() {
       BufferedReader in;
       String line;
       try {
           in = new BufferedReader(new FileReader("names.txt"));

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

               if(!line.equals(""))
               bTree.insert(line);
           }
           in.close();
       } catch (IOException e) {
           System.out.println("There was a problem:" + e);
       }

   }

}

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