Question: Write a Java Program that performs the following functionalities: A. Enter a new main sentence B . Find a String C . Find all incidents

Write a Java Program that performs the following functionalities:

A. Enter a new main sentence

B. Find a String

C. Find all incidents of a String

D. Find and Replace a String

E. Replace all the incidents of a String

F. Count the number of words

G. Count a letters occurrences

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

The program will display a menu with each option above, and then ask the user to enter their choice. There should also be a tenth option (option J) to quit, in which case, the program will simply display a goodbye message.

Based on the users choice, the program will perform the chosen functionality - more details are given below for each one. Make sure to include proper output for all cases (such as instructions, questions to the user, or directions telling the user to input something specific). Make sure the menu uses letters not numbers!

Note: The program should keep running and displaying the menu after each functionality, until the user chooses to exit! Make sure to get a default sentence from the user before going into the menu options.

Descriptions of Each Option:

A. Enter a new main sentence: Ask the user to input a new sentence. This sentence will be later on used in the other menu operations ex: (Find a String, Find all incidents of a String, etc.)

B. Find a String: Ask the user to input a word, then display the index of the first occurrence of the word in the main sentence. If the word is not found make sure to output the word is not found!

TIP: If you get a runtime error because the word is not found, then your if statement structure is incorrect!

C. Find all incidents of a String: Ask the user to input a word, then display the index of every occurrence of that word in the main sentence. If the word is not found make sure to output the word is not found!

D. Find and Replace a String: Prompt the user to input a word, then ask the user to input another new word for replacement. Lastly, locate the word in the main sentence and replace it with the new word. If the user inputs a string thats not found in the main sentence make sure to output the word is not found. Note: This option only replaces the first occurence of the String.

E. Replace all incidents of a String: Prompt the user to input a word, then ask the user to input another new word for replacement. Lastly, locate the all the occurrences of the word in the main sentence and replace all of them with the new word. If the user inputs a string thats not found in the main sentence make sure to output the word is not found.

F. Count the number of words: Display the number of words in the main sentence. TIP: Think of what usually separates words and just count the number of occurrences for that.

G. Count a letters occurrences: Prompt the user to enter a letter. Store that letter in a char variable and then display how many times the char occurs in the main sentence.

H. Count the total number of letters: Store the main sentence in a temporary variable, try to trim it from spaces. Then use the length method to count how many letters/characters there are in the main sentence.

I. Delete all the occurrences of a word: Prompt the user to enter a word, then delete all the occurrences of that word in the main sentence then display the updated main sentence.

Note: If the user types at, then all occurrences of at should be removed. Example: station becomes stion. On the other hand, if the user types at with spaces then station is not altered.

J. Exit: Simply display a goodbye message. End the program.

Sample Run

________________________________________________________________________________________________________

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: a

Input a new Main Sentence: Java is cool

The new Main Sentence is:

Java is cool

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: b

Enter the search string: lama

lama is not found

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: b

Enter the search string: cool

cool found at 8

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: c

Enter the string you want to find all incidents for: o

o found at: 9

o found at: 10

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: d

Enter the search string: o

Enter the String you want to replace the found String with:z

Java is czol

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: e

Enter the search string: a

Enter the replacing string: m

Jmvm is czol is changed to:

Jmvm is czol

A. Enter a new Main Sentence

B. Find a String

C. Find all incidents of a string

D. Find and Replace the String

E. Replace all incidents of a string to another one

F. Count the number of words

G. Count the number of occurrences of a letter

H. Count the total number of letters

I. Delete all the occurrences of a word

J. Exit

Enter your choice: f The number of words are: 3 A. Enter a new Main Sentence B. Find a String C. Find all incidents of a string D. Find and Replace the String E. Replace all incidents of a string to another one F. Count the number of words G. Count the number of occurrences of a letter H. Count the total number of letters I. Delete all the occurrences of a word J. Exit

Enter your choice: g Enter a letter to count the number of occurrences: z The number of letters are: 1 A. Enter a new Main Sentence B. Find a String C. Find all incidents of a string D. Find and Replace the String E. Replace all incidents of a string to another one F. Count the number of words G. Count the number of occurrences of a letter H. Count the total number of letters I. Delete all the occurrences of a word J. Exit Enter your choice: h The number of letters are: 10 A. Enter a new Main Sentence B. Find a String C. Find all incidents of a string D. Find and Replace the String E. Replace all incidents of a string to another one F. Count the number of words G. Count the number of occurrences of a letter H. Count the total number of letters I. Delete all the occurrences of a word J. Exit Enter your choice: i Enter a word to delete: czol The new Main Sentence is: Jmvm is A. Enter a new Main Sentence B. Find a String C. Find all incidents of a string D. Find and Replace the String E. Replace all incidents of a string to another one F. Count the number of words G. Count the number of occurrences of a letter H. Count the total number of letters I. Delete all the occurrences of a word J. Exit Enter your choice: j Bye!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!