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
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...
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 |...
   QUESTION (answer all parts of the question in a MINIMUM of 2 paragraphs, using in-text...
   QUESTION (answer all parts of the question in a MINIMUM of 2 paragraphs, using in-text citations and references). Refer to the Genetic-Genomic Nursing Competencies and the ANA Code of Ethics, and any other current professional nursing literature you choose to include. Answers should be double-spaced, in paragraph format, with complete sentences and proper grammar. If the fetus is diagnosed with CF and Lisa chooses to terminate her pregnancy, after being properly educated and counseled about the risks, what is...
Please write a java program to write to a text file and to read from a...
Please write a java program to write to a text file and to read from a text file.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT