Write a Java program to simulate the Find and Replace functions found in word processors.
- String variables
Write a program which can replace a phrase found within a text paragraph with a second phrase. You program needs the following.
- Asks the user to enter a String to search for to be replaced, findThis.
- Asks the user to enter another String to replace the above String, replaceWith.
- You can hard code or ask the user to enter the paragraph of text to search through, inThis.
- Asks the user if they want to replace the first or all occurrences of findThis.
- If the user chooses the first occurrence, find the first occurrence of the String, findThis, inside the String , inThis, and replace it with the String, replaceWith.
- If the user chooses to replace all, replace all the occurrences of findThis in inThis with replaceWith.
- Output the original paragraph of text along with the new paragraph.
- If the search string, findThis, is not found in the paragraph, inThis, report that the string was not found.
- Code Requirements:
- For an A on the project you must use the indexOf() and substring() methods to find and replace the strings. These two methods will be tested on the AP exam and you should practice using them.
- If you use the replaceAll() or replaceFirst() methods, you will earn at best a B on the assignment. These methods work, but are not required for the AP exam.
AP College Board test prep videos
Bill Barnum’s AP Computer Science A test prep videos