Question: Instructions: Use this word document to complete the lab assignment. Complete all the questions in this document and upload the final word file to Moodle.

Instructions:
Use this word document to complete the lab assignment.
Complete all the questions in this document and upload the final word file to Moodle.
The word file should be renamed as StudentID_Lab1.docx when uploading it to Moodle.
Upload the programming files (in .java format) to Moodle for individual questions.
Please ensure the code is formatted correctly when pasting it in the word file.
Objective: In this lab, you will implement a recursive function to calculate the Fibonacci series and explore how recursion can be used to solve problems with a recursive structure. You will also learn how to empirically calculate the computational time of a code.
Question 1:
Write a Java program that includes a recursive function to calculate the Fibonacci series up to a given term. The Fibonacci series is defined as follows:
The first two terms are 0 and 1.
The subsequent terms are the sum of the two preceding terms.
Mathematically: F(0)=0, F(1)=1, and for n >=2, F(n)= F(n-1)+ F(n-2).
Implement a recursive function called calculateFibonacci(int n) that calculates the nth term of the Fibonacci series using recursion.
In the main method, prompt the user to enter an integer n (where n >=0) and then call the calculateFibonacci function to compute and display the nth term of the Fibonacci series. The program should not accept non-negative integer n and an error message must be displayed. The program should also calculate and display the time it takes to complete execution (Hint: Use System.nanoTime to get current time snapshot in nanoseconds).
Complete the following table using your program:
Integer n Fibonacci Sequence (F(n)) Elapsed Time (s)
1
3
5
10
15
20
Insert your Java code in the box below. Also, submit the java code on Moodle.

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!