Question

In: Computer Science

using java, parse a text file to answer the following question: -list sentences with the maximum...

using java, parse a text file to answer the following question:
-list sentences with the maximum number of occurences of the word “the” in the whole file and also list the corresponding frequency. (cannot use hash maps)

example output:
the:3:The day had came to leave before the storm.
What hit the back bumper of the car before the window cracked?
The classroom doors where shut closed before the students open the project.

Solutions

Expert Solution

import java.io.*;
public class TheWord
{
   public static void main(String[] args) throws IOException
   {
       File f1= new File("input.txt");
       BufferedReader br = new BufferedReader(new FileReader(f1));
       int count=0,present;
       String[] words=null;
       String s;
       String search="the";
       while ((s=br.readLine())!=null)
       {
           words=s.split(" ");
           present=0;
           for (String word:words)
           {
               if (word.equalsIgnoreCase(search))
               {
                   count++;
                   present=1;
               }
               if (present==1)
                   break;
           }
       }
       System.out.println("the : "+count);

   }
}


Related Solutions

given a input file, parse it and answer the following frequency related questions, using java. -list...
given a input file, parse it and answer the following frequency related questions, using java. -list the most frequent word(s) in the whole file and its frequency. -list sentence(s) with the max. number of occurrences of the word “of” in the entire file and also list the corresponding frequency. program has two arguments; 1st : path to the input text file 2nd : name prefix for the output files ex. $ java assgn1 “./input.txt” “output” outputs: for each question create...
How to read a text file and store the elements into a linked list in java?...
How to read a text file and store the elements into a linked list in java? Example of a text file: CS100, Intro to CS, John Smith, 37, 100.00 CS200, Java Programming, Susan Smith, 35, 200.00 CS300, Data Structures, Ahmed Suad, 41, 150.50 CS400, Analysis of Algorithms, Yapsiong Chen, 70, 220.50 and print them out in this format: Course: CS100 Title: Intro to CS Author: Name = John Smith, Age = 37 Price: 100.0. And also to print out the...
java question: How would you be able to store a matrix from a text file into...
java question: How would you be able to store a matrix from a text file into a linked or doubly linked list, if you cannot use 2D arrays? input example: 1 2 3 4 1 3 2 4 4 2 3 1
In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name "Test" and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named "361" 5-Copy file "Test" to...
Java Code using Queue Write a program that opens a text file and reads its contents...
Java Code using Queue Write a program that opens a text file and reads its contents into a queue of characters, it should read character by character (including space/line change) and enqueue characters into a queue one by one. Dequeue characters, change their cases (upper case to lower case, lower case to upper case) and save them into a new text file (all the chars are in the same order as the original file, but with different upper/lower case) use...
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
This is a python file Reads information from a text file into a list of sublists....
This is a python file Reads information from a text file into a list of sublists. Be sure to ask the user to enter the file name and end the program if the file doesn’t exist. Text file format will be as shown, where each item is separated by a comma and a space: ID, firstName, lastName, birthDate, hireDate, salary Store the information into a list of sublists called empRoster. EmpRoster will be a list of sublists, where each sublist...
C++ coding question From the text file given to you- “worldpop.txt”, perform the following tasks using...
C++ coding question From the text file given to you- “worldpop.txt”, perform the following tasks using Boolean function. PS-*Write separate codes for each task* Task 1. Display the names of the countries with: 1. Population >=1000,000,000 2. Population <= 1000,000 Task 2. Display the names of the first 10 countries Task 3. Display the names of the last 10 countries contents of worldpop.txt: Afghanistan 32738376 Akrotiri 15700 Albania 3619778 Algeria 33769669 Andorra 72413 Angola 12531357 Anguilla 14108 Argentina 40677348 Armenia...
Draw parse trees for nine strings in question one, using their grammars. For the following grammars,...
Draw parse trees for nine strings in question one, using their grammars. For the following grammars, write the leftmost derivation for the strings given with each. Next to each derivation step, write the number of the rule used. Do not combine steps.   grammar (3 rules), Σ = {a, b}: S -> aSbS | bSaS | ε strings (3): ab, baab, bbaa grammar (6 rules), Σ = {0, 1}: S -> A1B A -> 0A | ε B -> 0B |...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT