The program should start by asking the user for the word to be searched for. Then the words in the file should be counted and compared if the keyword exists or not. A printout should be made where the user is informed if the keyword existed or not, how long (in milliseconds) the search took and how many words the file contains in total. As an argument to the program, the name of the file to be searched should be specified. If no argument is specified to the program, the file wordlist1.txt is to be used.
Java Program /The Output attached by image
Overview
You should enter this task, ask the user for a word and then search for a file to see if that word is among the words in the file.
Task
This exercise comes with three text files named wordlist1.txt, wordlist2.txt and wordlist3.txt. These files contain a large amount of words in English. Each file contains more and more words. Each word in these files is on a separate line and the words contain only lowercase letters. Your task is to write a program that reads all these words from the file and checks if a keyword, which the user entered, is among the entered words. The program should also count the total number of words contained in the file used. The program should measure how long it takes to complete the search, ie how long it takes to read all the words and check if the keyword is among the words or not.
The program should start by asking the user for the word to be searched for. Then the words in the file should be counted and compared if the keyword exists or not. A printout should be made where the user is informed if the keyword existed or not, how long (in milliseconds) the search took and how many words the file contains in total.
As an argument to the program, the name of the file to be searched should be specified. If no argument is specified to the program, the file wordlist1.txt is to be used.
Tip
• The search does not have to take into account the exact matching of the keyword parts of words go well. If e.g. the user wants to search for only the letter a, it is enough that a word contains the letter a.
Step by step
Solved in 3 steps with 1 images