Question

In: Computer Science

USING JAVA A method that parses the valid word file to a list of Strings. You...

USING JAVA

  • A method that parses the valid word file to a list of Strings. You may use a loop in the parsing method.
  • A nonrecursive method that prints the input String, makes the first call to the recursive anagramizer method, sends the result to the filter method, and prints the filtered result. You may use this code:
  • private void anagramize(String inString) {
  •         System.out.println("input string: " + inString);
  •         List < String > l = filter(anagramizeRecursive(inString.toLowerCase()));
  •         System.out.println("Anagrams: " + l);
  • }

Solutions

Expert Solution

package File;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileReader;

import java.io.IOException;

public class FileWordSearch

{

public static void main(String[] args) throws IOException

{

File f1=new File("input.txt"); //Creation of File Descriptor for input file

String[] words=null; //Intialize the word Array

FileReader fr = new FileReader(f1); //Creation of File Reader object

BufferedReader br = new BufferedReader(fr); //Creation of BufferedReader object

String s;

String input="Java"; // Input word to be searched

int count=0; //Intialize the word to zero

while((s=br.readLine())!=null) //Reading Content from the file

{

words=s.split(" "); //Split the word using space

for (String word : words)

{

if (word.equals(input)) //Search for the given word

{

count++; //If Present increase the count by one

}

}

}

if(count!=0) //Check for count not equal to zero

{

System.out.println("The given word is present for "+count+ " Times in the file");

}

else

{

System.out.println("The given word is not present in the file");

}

  

fr.close();

}

}


Related Solutions

using java, parse a text file to be able to list the word(s) with the highest...
using java, parse a text file to be able to list the word(s) with the highest frequency in a sentence across all sentences in the whole file, also print its frequency and the corresponding sentence. cannot use hash maps. assume text file will be multiple paragraphs long.
Java Programming Using the class below, please ), write a static method called parse that parses...
Java Programming Using the class below, please ), write a static method called parse that parses a String for balanced parentheses. we seek only to determine that the symbol ‘{‘ is balanced with ‘}’. parse accepts a single String parameter and returns an int. If parse returns a minus 1, then there are no errors, otherwise, parse should return the position within the String where an error occurred. For example parse(“{3 + {4/2} }”)   would return -1 parse(“{ { 4*X}”)...
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.
You are provided with an array of Strings and a list of Strings. Sort the elements...
You are provided with an array of Strings and a list of Strings. Sort the elements (1) in natural order, (2) in reverse natural order and (3) by the length of each String. You can fill in the details by using the following stub file: import java.util.Arrays; import java.util.Collections; import java.util.List; public class Midterm01 { public static void main(String[] args) { String[] arrayOfCities = { "Atlanta", "Savannah", "New York", "Dallas", "Rio" }; List<String> listOfCities = Arrays.asList("Atlanta", "Savannah", "New York", "Dallas",...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that...
Java 1.Write a method removeEvenLength that takes an ArrayList of Strings as a parameter and that removes all of the strings of even length from the list. 2. Given the following Vehicle interface and client program in the Car class: public interface Vehicle{ public void move(); } public class Car implements Vehicle{ public static void main(String args[]) Vehicle v = new Vehicle(); // vehicle declaration } The above declaration is valid? True or False? 3. Java permits a class to...
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...
Please use JAVA to do this: Write a method that takes four strings as parameter. The...
Please use JAVA to do this: Write a method that takes four strings as parameter. The first string should be a pokemon name, the second a pokemon type(either fire, water, or leaf, where water beats fire, fire beats leaf and leaf beats water), the third a pokemon name, and the fourth a pokemon type. The method should print out which pokemon has the advantage over the other based on their type. Example: Pokemon X(which is the fire type) has the...
Write a Java method to check whether a string is a valid password. Password rules: A...
Write a Java method to check whether a string is a valid password. Password rules: A password must have at least ten characters. A password consists of only letters and digits. A password must contain at least two digits. There are at least SIX functions/methods as the following: 1. menu() – to print the password’s rules. 2. getString() – to get the password from the user. 3. isPassword() – to check either the password is valid based on the given...
Java Question: COSC 2436 Lab 4 (Submit your Word file with answers) If you push the...
Java Question: COSC 2436 Lab 4 (Submit your Word file with answers) If you push the objects x, y, and z onto an initially empty stack, in what order will three pop operations remove them from the stack? What pseudocode statements create a stack of the three strings "Jill", "Jane", and "Joe", in that order with "Jill" at the top? Suppose that s and t are empty stacks and a, b, c, and d are objects. What do the stacks...
I have a Python code that reads the text file, creates word list then calculates word...
I have a Python code that reads the text file, creates word list then calculates word frequency of each word. Please see below: #Open file f = open('example.txt', 'r') #list created with all words data=f.read().lower() list1=data.split() #empty dictionary d={} # Adding all elements of the list to a dictionary and assigning it's value as zero for i in set(list1):     d[i]=0 # checking and counting the values for i in list1:     for j in d.keys():        if i==j:           d[i]=d[i]+1 #Return all non-overlapping...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT