Problem Description
Write a JAVA program that will read all words from a passage and store them in BST. The program then will display a menu and perform the following task:
- Delete a word. If a word exists, update the word frequency otherwise print word not exist.
- Search a word. If a word exists, print the word and its frequency otherwise print not exist.
- Add a new word. If the word is in the passage, update its frequency.
- Print all words and their frequency in ascending order.
Input
The input of this program is a passage. A passage consists of N words and symbols. Symbols that will be considered in the passage are full stop (.), comma (,), question mark (?) and exclamation mark (!). The passage will have M unique words, where the M is less than or equal to N.
Followed by the input code and the required data as specified in the sample input-output.
Input
Stay at home, stay safe and stay healthy. Practice social distancing at work and at home. Help reduce the risk of infection and preventing covid19. Together we break the chain of covid19. #kita jaga kita. Hapuskan covid19!.
2
pandemic
44
5
where
the first line is the input text
the second line is number of menu 2 - Delete word
the third line is wrong input number (44 - out of range input value)
the forth line is number of menu 5 - Exit
Output
Menu:
1. Add new word.
2. Delete word.
3. Search word.
4. Print all words and its frequency.
5. Exit.
Input code: 2
Enter word to be deleted: pandemic
The word pandemic is not in the passage.
Menu:
1. Add new word.
2. Delete word.
3. Search word.
4. Print all words and its frequency.
5. Exit.
Input code: 44
Invalid code, Enter code 1-5.
Menu:
1. Add new word.
2. Delete word.
3. Search word.
4. Print all words and its frequency.
5. Exit.
Input code: 5
Bye..