Question: package recursion; import java.util.Scanner; public class Recursion { // Class example public static int sum_up(int n) { if (n return 0; } else { return

| package recursion; | |||||||||||||||||||||||||||||||||||||||||||||
| import java.util.Scanner; | |||||||||||||||||||||||||||||||||||||||||||||
| public class Recursion { | |||||||||||||||||||||||||||||||||||||||||||||
| // Class example | |||||||||||||||||||||||||||||||||||||||||||||
| public static int sum_up(int n) { | |||||||||||||||||||||||||||||||||||||||||||||
| if (n | |||||||||||||||||||||||||||||||||||||||||||||
| return 0; | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| else { | |||||||||||||||||||||||||||||||||||||||||||||
| return n + sum_up(n-1); | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| // Class example | |||||||||||||||||||||||||||||||||||||||||||||
| public static int sum_up_tail(int n) { | |||||||||||||||||||||||||||||||||||||||||||||
| return sum_up_tail(n, 0); | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| public static int sum_up_tail(int n, int tmp) { | |||||||||||||||||||||||||||||||||||||||||||||
| if (n | |||||||||||||||||||||||||||||||||||||||||||||
| return tmp; | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| else { | |||||||||||||||||||||||||||||||||||||||||||||
| return sum_up_tail(n-1, tmp+n); | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| } | |||||||||||||||||||||||||||||||||||||||||||||
| // Activity 4 int fact(int n) | |||||||||||||||||||||||||||||||||||||||||||||
| // Activity 4 int fib(int n) | |||||||||||||||||||||||||||||||||||||||||||||
| // Activity 4 int gcd(int num1, int num2) | |||||||||||||||||||||||||||||||||||||||||||||
| // Project 4 int power (int x, int y) | |||||||||||||||||||||||||||||||||||||||||||||
| // Project 4 balance(int x, int y) | |||||||||||||||||||||||||||||||||||||||||||||
| // Project 4 int Ackermann(int m, int n) | |||||||||||||||||||||||||||||||||||||||||||||
| // Project 4 playGuessingGame(int m) | |||||||||||||||||||||||||||||||||||||||||||||
}
|
Programming Project - Recursion 1) Review the material about recursion 2) If you have not done so already, download the source code from https:/lgithub.com/CGCC-CS! 205activity4.git. The file Project4.java is a driver class that tests the methods from the activity & the methods below 3) Add the following methods to your Recursion class: A. A recursive Java method called power(x,y) to find x raised to the power of y. You can assume that y>=0. Note that your method must be recursive. You will receive no credit if you call Math.pow0. B. Add a recursive Java method called balance (x,y) to compute the floor of the average of x & y as follows: If the two parameters are within 1 of each other, return the smaller number Otherwise, subtract one from the larger parameter and add one to the smaller parameter and return balance of those two numbers C. A recursive Java method called Ackermann (m,n) to compute the Ackerman function defined as follows: ifm=0 If m > 0 and n=0 A(m, n) = A(m-1, 1) A(m 1, A(m,n -1)) if m > 0 and n >0. The Ackermann function grows very quickly, so you may run into stack overflows when m>3. You can see a table of correct values here: https://en.wikipedia.org/wiki/ Ackermann function D. A method called playGuessingGame (m) that lets the user play a guessing game. The method will pick a random number between 0 & m and prompt the user enter a guess from 0 to m. If the user does not guess the number then they should be told whether their guess was higher or lower than the number then display a new range to choose from. Your playGuessingGame method should call a recursive helper method that prints the range the user should guess between. Uncomment all the test code in the Project4 driver class and include sample output for all the methods you wrote for the activity & project in your submission document. 4)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

