Question: Need solutions to these recursion problems! The Recursion Class: The name of your class shall exactly be Recursion . This class will only contain static

Need solutions to these recursion problems!

The Recursion Class:

The name of your class shall exactly be Recursion.

This class will only contain static methods to solve each recursion problem.

You will not need to instantiate this class and each method can be called in a static way: Recursion.methodName().

Data Fields:

No Data Fields allowed.

Constructors:private Recursion():

This is the only constructor that is allowed.

This constructor should be set to private to prevent the class from being able to be instantiated.

Methods:

Implement each of the methods described below using recursion.

You must solve each problem with recursion, no loops are allowed.

Each method should be declared as static.

Recursive Method 01: Bunny Ears

Prompt: On the planet Bunnytopia, rabbits are either even or odd. An even rabbit has 4 ears, and an odd rabbit has 5 ears. You are to write a recursive method which accepts a total number of bunnies as input (n). Your method should compute and return the total number of ears given n bunnies.

Additional Requirements:

Your method MUST use recursion.

Your method is NOT allowed to use any loops or multiplication to compute the results.

Your method must be public and static.

Your method must return the final result.

Provide one or more parameters for your method (you can think about this as part of the design.)

Your method must be named bunnyEars.

Reminder: Your class is not allowed to have any data fields.

Examples:For 5 bunnies, there would be a total of 23 ears

5 + 4 + 5 + 4 +5 = 23

For 8 bunnies there would be a total of 36 ears

5 + 4 + 5 + 4 +5 + 4 + 5 + 4 = 36

In your RecursionMain class, ask the user to enter the number of bunnies, and display the total number of ears, when the user chooses to run this option.

Recursive Method 02: Zeno's Racecourse Paradox

Prompt: A simplified version of the Greek philosopher Zeno's racecourse paradox goes like this: A runner on a race course can never reach the end of the race course because they must first travel half the distance to the end. After the runner travels this first half distance, they must then travel half of the remaining distance. Once the runner reaches half of the remaining distance they must still travel half of the next remaining distance. On and on it goes infinitely dividing the distance so that the runner can never actually reach the end. Your job is to write a recursive method that takes an integer n (number of iterations) and a double totalDistance (that the runner must run) as parameters, and show how far the runner would have traveled after n iterations.

Additional Requirements:

Your method MUST use recursion.

Your method is NOT allowed to use any loops or multiplication to compute the results.

Your method must be public and static.

Your method must return the final result.

Provide one or more parameters for your method (you can think about this as part of the design.)

Your method must be named zenosRaceParadox.

Reminder: Your class is not allowed to have any data fields.

Example:If the distance was 100 ft and the number of iterations was 4 then the total distance traveled would be 93.75 ft

50 ft + 25 ft + 12.5 ft + 6.25 ft = 93.75 ft

In your RecursionMain class, ask the user to enter the total distance and the number of iterations, and display the total distance traveled, when they choose this option.

Recursive Method 03: Substrings

Make sure to call this method substrings.

With a string and a potential substring, write a recursive function that returns the number of times the given subtring appears in the string.

i.e. string is "hello hello world" and the substring is "lo". The result should be 2 since there are 2 "lo"'s in the string

i.e. string is "The dog went through the doghouse to get to the other side" and the substring is "the" the result should be

In your RecursionMain class, ask the user to enter a string and substring and display the results, when this option is chosen.

HINT: I solved this one with 1 base case and 2 recursive cases.

Recursive Method 04: Pair Sums

Make sure to call this method pairSums.

Given an array of ints, use recursion to sum up a pair of ints at a time until you end up with a single sum

NOTE: You must solve this problem using only recursion and no loops. The trick is to think about what your base case(s) and recursion case(s) should look like and what parameter(s) each recursive call may need.

HINT: I solved this one with 1 base case and 2 recursive cases.

i.e. Input > {1, 2, 3, 4, 5}

step 1: {3, 5, 7, 9} ----- (this comes from 1+2, 2+3, 3+4, and 4+5)

step 2: {8, 12, 16} ----- (this comes from 3+5, 5+7, 7+9)

step 3: {20, 28} ------- (8+12, 12+16)

step 4: {48}

In your RecursionMain class, ask the user to enter a sequence of positive integers and -1 to end the input, when this option is chosen.

The RecursionMain Class:

The name of your class shall exactly be RecursionMain.

Implement a simple menu system in this class with the following options?

1. Bunny Ears

2. Zeno's Race Paradox

3. Substrings

4. Pair Sums

5. Exit Program

This menu should repeat until the user chooses to exit.

Once the user chooses an option, you should prompt the user to enter any information that option needs in order to solve the requested problem.

Pass the user input to the chosen method and display the results of that method.

Make sure your output is organized and easily understandable.

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!