Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

From the below, create class which implements RecusiveMethods ---------------------------------------------------------------------------------------- import java.security.SecureRandom; /** * * DO NOT CHANGE THIS CODE * */ public class RecursiveMain {

From the below, create class which implements RecusiveMethods

----------------------------------------------------------------------------------------

import java.security.SecureRandom;

/**

*

* DO NOT CHANGE THIS CODE

*

*/

public class RecursiveMain {

public static void main(String[] args) {

SecureRandom secureRandom = new SecureRandom();

long[] fibonacciArray = {0,1,1,2,3,5,8,13,21,34,55,89,144,233,377};

long[] factorialArray = {1,1,2,6,24,120,720,5040,40320,362880,3628800,39916800,479001600,6227020800l,87178291200l};

long[] fArray = {3,6,15,48,195,978,5871,41100,328803,2959230,29592303,325515336,3906184035l,50780392458l,710925494415l};

RecursiveMethods myRecursive = new MyRecursive();

for(int i = 0; i < fibonacciArray.length; i++) {

if(myRecursive.fibonacci(i) == fibonacciArray[i]) {

System.out.println("[OK] - fibonacci(" +i+") = "+ fibonacciArray[i]);

} else {

System.out.println("[XX] - fibonacci(" +i+") expected "+ fibonacciArray[i] + " but found " + myRecursive.fibonacci(i));

}

}

for(int i = 0; i < factorialArray.length; i++) {

if(myRecursive.factorial(i) == factorialArray[i]) {

System.out.println("[OK] - factorial(" +i+") = "+ factorialArray[i]);

} else {

System.out.println("[XX] - factorial(" +i+") expected "+ factorialArray[i] + " but found " + myRecursive.factorial(i));

}

}

for(int i = 0; i < fArray.length; i++) {

if(myRecursive.f(i) == fArray[i]) {

System.out.println("[OK] - f(" +i+") = "+ fArray[i]);

} else {

System.out.println("[XX] - f(" +i+") expected "+ fArray[i] + " but found " + myRecursive.f(i));

}

}

}

}

----------------------------------------------------------------------------------------

 
/**
 * 
 * DO NOT CHANGE THIS CODE
 *
 */
public interface RecursiveMethods {
 
 /**
 * 
 * @param n
 * @return - the fibonacci value at n
 */
 public long fibonacci(int n);
 
 /**
 * 
 * @param n
 * @return - n!
 */
 public long factorial(int n);
 
 /**
 * WHERE
 * 
 * f(n) = n * f(n-1) + 3
 * f(0) = 3
 * 
 */
 public long f(int n);
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Strategic Database Technology Management For The Year 2000

Authors: Alan Simon

1st Edition

155860264X, 978-1558602649

More Books

Students also viewed these Databases questions

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago