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.
![Exempel
c:\>java Uppgift2
Enter the word to search for>hello
The file 'wordlistl.txt' contains 55899 words
The word 'hello' exists in this file
The search took 108 ms
c:\>java Uppgift2 wordlist2.txt
Enter the word to search for>hello
The file 'wordlist2.txt' contains l09583 words
The word 'hello' exists in this file
The search took 169 ms
c:\>java Uppgift2 wordlist3.txt
Enter the word to search for>hello
The file 'wordlist3.txt' contains 354986 words
The word 'hello' exists in this file
The search took 296 ms
c:\>java Uppgift2
Enter the word to search for>xyz
The file 'wordlistl.txt' contains 55899 words
The word
Xyz' does not exists in this file
The search took 116
ms
c:\>java Uppgift2 not-exist.txt
Enter the word to search for>java
Exception in thread "main" java.io.FileNotFoundException: not-
exist.txt (we cann't find this file)
at java.base/java.io.FileInputStream.open0 (Native Method)
at
java baseLiava:ie«FileInrutstesam.eren(FileInputStream.java:216)
at
java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at javakassLiava:utik&canner-<init (Scanner.java:639)
at Uppgift2.main (Uppgift2.java:21)](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe8260224-635c-426e-a960-28f2cf28de1f%2Ff4f048d6-5293-4a37-883f-91283773944d%2Fxv68brw_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)