You are to write a program that will complete the following tasks:
- Start: Prompt the user to give you a sentence (String) of any kind. Send the String to the constructor of the second class.
- You will need an instance of the Scanner class to take the String from the user. Use the nextLine() method.
- After the input is set, you have the String from the user, you will give the user a menu of choices that will manipulate the String, 5 menu items needed:
- Option1: Count the number of occurrences of a single character in the String. You will take user input for the character you will search for.
- So if the String is “fellow fall” and the user chooses l to search the method will return 4.
- “why the white whale wallows” and user asks for w the method will return 5.
- Option2: Count the words in the String, ignore white space “This is a string” and “This is a String” would both count 4 words. The method will return 4.
- Option3: Return the String as a String without spaces.
- If the string is “why the white whale wallows” the method returns a String “whythewhitewhalewallows”
- Option4: Change the original input String (just reset the String you took at the startup to a new String given by the user).
- Option5: Exit.
- Option1: Count the number of occurrences of a single character in the String. You will take user input for the character you will search for.
- According to whatever choice the user request you will use if/switch statement to call the method that handles that chore.
- The program will continue to run until the user chooses the exit choice. Use a do/while loop for this purpose.
- Use the Scanner class to take user input.
Hints:
You can use charAt() to count a specific character in the given sentence, and split() function to count the number of words in the given sentence.
The steps you should take to make it easier:
Go step by step.
- First get the user input working.
- Then get the menu to print out. You can use numbers to represent each menu option.
- Then get the if/switch statement set up.
- Then get exit to work.
- Then get the resetting the String to work.
- Then work on counting letters or words.
- Wrap up your code (from step2 to step7) inside a loop. The loop should terminate when the user input exit option.


0 comments