Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

DESCRIPTIONFor this assignment, you are to complete the program given below. This program builds a table containing the all of the words in a given text file and the number of occurrences of each Word...

1 answer below »
DESCRIPTIONFor this assignment, you are to complete the program given below. This program builds a table containing the all of the words in a given text file and the number of occurrences of each
Word Occurrenceslake 14he XXXXXXXXXX42they 31person 8etc.
Note that the words in the table do not have to be in any particular order. The pre and postcondition specification for each function is given. For those functions you are to complete, be sure to follow the pre and postcondition specifications exactly. You are to test your completed program using your own test files. Such test files can be created using notepad, or any simple editor that does not add word processing characters. The name of the data file should be .txt, and you should enter the full file name including the .txt extension when running the program. The text file should be placed in the same directory as the source file.
NOTES(1) Your program should work for any text file including any characters.(2) Words differing only in upper/lower case should be considered the same word (e.g., The and the).(3) You are encouraged to use the debugger in Netbeans for debugging your program.(4) Make sure that you test your program well. I will test all programs with my own test files.
//=========================================================================== // WORD COUNT PROGRAM //=========================================================================== // This program will input any text file and output a table of word counts // containing each word in the document and the number of times that each // word appears. Maximum number of words is 500. //-------------------------------------------------------- XXXXXXXXXXimport java.io.File; import java.io.FileNotFoundException; import java.util.Scanner;   public class Main {     public static void main(String[] args) {          // Variable Declarations         // -- keyboard input XXXXXXXXXXScanner keyboard_input = new Scanner(System.in);          // -- file input XXXXXXXXXXboolean file_found = false; XXXXXXXXXXString file_name; XXXXXXXXXXScanner file_input;              // --line buffer         // (Index [0] – current char position, index [1] – buffer contents XXXXXXXXXXString[] line_buffer = new String[2];                  // -- word count table (as parallel arrays XXXXXXXXXXString[] word_list = new String[500]; XXXXXXXXXXint[] word_counts = new int[500];           // File Processing         // -- open file XXXXXXXXXXwhile(!file_found) { XXXXXXXXXXtry {                 // get file name XXXXXXXXXXSystem.out.println("Enter file name (including .txt): "); XXXXXXXXXXfile_name = keyboard_input.nextLine();                  // -- open file for reading XXXXXXXXXXfile_input = new Scanner(new File(file_name)); XXXXXXXXXXfile_found = true;           } XXXXXXXXXXcatch(FileNotFoundException e) { XXXXXXXXXXSystem.out.println("File " + file_name + " not found."); XXXXXXXXXXSystem.out.println("Please re-enter");           }         }                     // -- process file XXXXXXXXXXprocessFile(word_list, word_counts, file_input);          // -- display word counts XXXXXXXXXXdisplayTable(word_list, word_counts);     }       // Supporting Methods      public static boolean isLetter(char c)      //---------------------------------------------------------------------------     // INPUT:       c     // PRECOND:     None.     // OUTPUT:           // POSTCOND:    If c between 'a' ... 'z' or 'A' ... 'Z', returns true,     // XXXXXXXXXXelse, returns false.     //---------------------------------------------------------------------------     {  } XXXXXXXXXXpublic static String scanWord(String[] buffer)     //---------------------------------------------------------------------------     // INPUT:       buffer     // PRECOND:     buffer[0] and buffer[1] not equal to empty string.     // XXXXXXXXXXbuffer[0] contains only digit characters.                     // XXXXXXXXXXint(buffer[0]) , buffer     // POSTCOND:    Returns next word in buffer as function value.     // XXXXXXXXXXint(buffer[0]) at first letter of next word, if another letter     // XXXXXXXXXXfound, else at end of line character.         //---------------------------------------------------------------------------     {  }       public static boolean endOfBuffer(String[] buffer)     //---------------------------------------------------------------------------     // INPUT:       buffer     // PRECOND:     buffer[0] and buffer[1] not equal to empty string.     // XXXXXXXXXXbuffer[0] contains only digit characters.                     // XXXXXXXXXXint(buffer[0])      // POSTCOND:    If at end of buffer, returns true, else returns false.     //---------------------------------------------------------------------------     {  }       public static String[] readLine(Scanner in_file)     //---------------------------------------------------------------------------     // INPUT:       in_file     // PRECOND:     open(in_file) and not at end of file     //     // OUTPUT:           // POSTCOND:    Returns next line from in_file and returns as a line buffer     // XXXXXXXXXXi.e., index[0] contains line length, index[1] contains line)     //---------------------------------------------------------------------------     {  }       public static void updateTable(String word, String[] words, int[] counts)     //---------------------------------------------------------------------------     // INPUT:       word, words, counts     // PRECOND:     len(words) > 0, len(counts) = len(words).     //     // OUTPUT:      words, counts     // POSTCOND:    If word equal to words[i], counts[i] incremented by one.     // XXXXXXXXXXOtherwise, adds word to words and sets corresponding element     // XXXXXXXXXXin counts to one.     //---------------------------------------------------------------------------     {  }       public static void displayTable(String[] words, int[] counts)     //---------------------------------------------------------------------------     // INPUT:       words, counts     // PRECOND:     len(words) > 0, len(counts) = len(words).     //     // OUTPUT:      None     // POSTCOND:    Displays corresponding words and counts on screen.     //---------------------------------------------------------------------------     {  }       public static void processFile(String[] words, int[] counts, Scanner in_file)     //---------------------------------------------------------------------------     // INPUT:       words, counts, in_file     // PRECOND:     len(words) > 0, len(counts) = len(words).     //     // OUTPUT:      words, counts     // POSTCOND:    First k elements of words contain the k unique words in file.     // XXXXXXXXXXFirst k elements of counts contains the corresponding number     // XXXXXXXXXXof occurrences of each word in words.     //---------------------------------------------------------------------------     {  }       public static boolean endOfFile(Scanner in_file)     //---------------------------------------------------------------------------     // INPUT:       in_file     // PRECOND:     open(in_file)     //     // OUTPUT:      Boolean     // POSTCOND:    Returns true if at end of file, otherwise, returns false.     //--------------------------------------------------------------------------     {  }  }


Answered 6 days After Feb 08, 2022

Solution

Arun Shankar answered on Feb 11 2022
111 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here