Question: Hello, can you please help with the two codes below. If possible, please add comments to help. Thank you!! Recursion Exercises - bjectives Module: To

Hello, can you please help with the two codes below. If possible, please add comments to help. Thank you!!

Recursion Exercises -bjectives

Module:

  • To write recursive solutions for basic problems that require iteration.
  • To identify and address base cases in a recursive method.

Reminders during development

  • Each of your solutions to the problems below should be in their own method.
  • If a method header is provided for a problem, then your solution should have that exact method header. Any changes to the method header will receive a zero for that problem.
  • You may not use fields in support of any of your methods. Anyone using a field to help write the logic of a method will receive a zero for that problem.
  • Each problem has several test cases, where the method is invoked and there is some type of output shown. You are required to test these cases with your submission. I should be able to run your code once and clearly see where you make the method calls and the expected output.
  • You may write other private recursive methods to support a method that you are required to write. You may not call these methods directly in your tests. You must call the public method described in each problem when testing.

Requirements

  • You should submit a single project with all your work for the six problems you were assigned
  • It should be easy to see each method in your code submission. Any messy or disorganized submissions will be penalized.
  • Any solutions that include any form of loop will not be accepted.
1

Write a recursive method that accepts a source string and a search string. The method should find all occurrences of the search string within the source string and replace them with an asterisk. The method should then return the new string.

Note: You may not use the replace(), replaceFirst() or replaceAll() methods from the string class. You should be identifying the position of the element using methods like indexOf() and then removing the search value using the substring() method. Note: You may use a loop, in this case only, to generate the sequence of asterisks that will be used to replace the search string. You will still need to use recursion to identify each matching search value.

Your method should have the following header:

public String asterisks(String source, String search) { //do something }

Test cases:

asterisks("beatrice eats each plum", "ea"); //b**trice **ts **ch plum asterisks("catch 22", "22"); //catch ** asterisks("bee been in your bonnet?", "be"); //**e **en in your bonnet? asterisks("are we there yet?", "yes"); //are we there yet?

2

Write a recursive method that accepts a string and determines if the string has any neighboring duplicate characters (i.e. the same two characters side-by-side in the string). Your method should have the following header:

public boolean duplicateNeighbors(String observe) { //do something }

Test cases:

duplicateNeighbors("abba"); //true duplicateNeighbors("abcdbadba"); //false duplicateNeighbors("bololobb"); //true duplicateNeighbors("aabcdef"); //true duplicateNeighbors("a"); //false

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!