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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

The Output:
when we run the program:
we run java + Javafile so the program has wordlist1.txt as default file 
if we want to search in differnt file so we can write java + javafile + name of the file we want to search in (wordlist2.txt or wordlist3.txt)
 
Exempel
c:\>java labb2
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 labb2 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 labb2 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 labb2
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 labb2 Demo.txt
Enter the word to search for>java
Exception in thread "main" java ieFileNotFeundException: finns-
inte.txt (We don't find this file)
at java base/java.io.FileInputStream.open0 (Native Method)
at
java baseLiavaie.filelngutstream.2pen(FileInputStream.java:216)
at
java.base/java.io.FileInputStream.<init>(FileInputStream.java:157)
at java baseLiava.util:Scanner-Sini> (Scanner.java:639)
at labb2.main(labb2.java:21)
Transcribed Image Text:Exempel c:\>java labb2 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 labb2 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 labb2 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 labb2 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 labb2 Demo.txt Enter the word to search for>java Exception in thread "main" java ieFileNotFeundException: finns- inte.txt (We don't find this file) at java base/java.io.FileInputStream.open0 (Native Method) at java baseLiavaie.filelngutstream.2pen(FileInputStream.java:216) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:157) at java baseLiava.util:Scanner-Sini> (Scanner.java:639) at labb2.main(labb2.java:21)
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education