230k views
3 votes
In this exercise, you are agiven a phrase that may or may not contain the word “plate”. If the word does exist, replace all occurances of “plate” with “bowl”, unless the word plate is plural. If it is plural, don’t replace it.

Example:

replacePlate("I ate off a plate.") --> "I ate off a bowl."
replacePlate("I set a plate on the plate.") --> "I set a bowl on the bowl."
replacePlate("I set a plate on the plates.") --> "I set a bowl on the plates."

This is in Java.

User RyanNHG
by
4.8k points

1 Answer

3 votes

Answer:

Is in the provided screenshot!

Step-by-step explanation:

Steps required to solve this problem

1) Take the input sentence and split it up into its separate words

2) Go through each word and see if it starts with the word plate.

- We need to check that it starts with plate and not if it equals plate so we can make sure that we keep any punctuation that is on the end of the word.

3) We also need to check if the word is not plates, so we can do that here.

4) If the word is plate, but not plate - then we can replace it with bowl

5) Now we just put our individual words back into a full sentence

In this exercise, you are agiven a phrase that may or may not contain the word “plate-example-1
User Jvtech
by
4.8k points