Write a Java program that reads in a paragraph of text from a file and prompts the user to enter a word to search for. The program should then output the number of times the word appears in the paragraph. Here are the basic steps to implement this program:

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

Write a Java program that reads in a paragraph of text from a file and prompts the user to enter a word to search for. The program should then output the number of times the word appears in the paragraph.

Here are the basic steps to implement this program:

  1. Prompt the user to enter the name of the input file.

  2. Read in the paragraph of text from the input file.

  3. Prompt the user to enter a word to search for.

  4. Search the paragraph for the word and count the number of times it appears.

  5. Output the number of times the word appears in the paragraph.

To implement step 4, you can use a similar approach to the example I provided in class:

  1. Split the paragraph into an array of words using the split() method.

  2. Iterate through each word in the array and compare it to the search word (ignoring case).

  3. If the word matches the search word, increment a counter variable.

Expert Solution
steps

Step by step

Solved in 5 steps with 4 images

Blurred answer
Knowledge Booster
Constants and Variables
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
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