Question: Chapter 1 6 Programming Challenge 9 , Starting out with Java, Tony Gladdis 4 th edition - Efficient Computation of Fibonacci Numbers ( Could I

Chapter 16 Programming Challenge 9, Starting out with Java, Tony Gladdis 4th edition - Efficient Computation of Fibonacci Numbers (Could I get the code for this with the added specifications, please)(The code you must retain you can use, I will add it to the end)
ADDED SPECIFICATIONS:
-In addition to your own iterative version, retain the textbooks recursive method.
-Call the recursive method once for each of the sequence positions and save this recursive computation time data for writeAnalysis().
-Modify the textbook Code Listing 16-18 to determine the average time required for each iterative Fibonacci number calculation over 10 runs.
-After each Fibonacci number is calculated (iterative and recursive), you will output the position and the number, e.g., Position: 45, number: 1836311903.---NOTE that the processing time to generate this output must not be included in the determination of the time required to compute the Fibonacci numbers.
-writeAnalysis() will be passed the raw overall runtime data for its analysis, formatting, and display.
-writeAnalysis() will output the recursive and average iterative computation time for each Fibonacci number.
ALREADY CODED RECURSIVE METHOD:
import java.util.Scanner;
public class Ch16_Pc09_TaylorC
{
public static void main (String [] args)
{
System.out.print("Enter a positive integer: ");
Scanner sc = new Scanner(System.in);
int number = sc.nextInt();
long currentTime = System.currentTimeMillis();
long previousTime;
long elapsedTime =0;
for (int k =0; k <=5; k++)
{
previousTime = currentTime;
System.out.print("The Fibonacci term at position ");
System.out.print((number + k)+" is ");
System.out.println(fib(number + k));
currentTime = System.currentTimeMillis();
elapsedTime =(currentTime - previousTime)/1000;
System.out.println("computed in "+ elapsedTime +" seconds. ");
}
}
public static long fib(long n)
{
if (n <=1)
return 1;
else
return fib(n-2)+ fib(n-1);
}
}

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!