Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA homework. Please do not copy code from other answers and please follow the instruction. Thank you! In this lab you will compute Fibonacci numbers

JAVA homework. Please do not copy code from other answers and please follow the instruction.

Thank you!

image text in transcribed

image text in transcribed

In this lab you will compute Fibonacci numbers using two different classes, each of which implements the same FindFib interface. Fibonacci is an interesting sequence. The first fibonacci number is 1. The second is 1, every subsequent number is the sum of the previous 2. To put it in math terms: F(n)= F (n-1) + F(n-2). The sequence looks like: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55... Hence Fibonacci(10) is 55. Fibonacci(6) = 8 etc. Assignment Requirements: Begin by creating an interface FindFib. It should have one method calculate_fib(). o calculate_fib() should take in an integer, and should return an integer. Next, create a class FibIteration that implements FindFib. o calculate_fib() should take in the same parameters and return the same type as the interface version. To calculate Fibonacci iteratively you start by checking if you are being asked to calculate the Fibonacci of 1 or 2, if so you return 1. Otherwise, you'll use a loop to keep adding up the previous numbers until you arrive at the answer. Next, create a class FibFormula that implements FindFib. o calculate_fib() should take in the same parameters and return the same type as the interface version. o To calculate Fibonacci by formula, plug in to Binet's Formula: F(n) = (((1+sqrt(5))/2)^n - ((1-sqrt(5))/2)^n) / sqrt(5) Create a driver program which prompts the user to enter a number, then calculate the fibonacci using both methods, and print the results. Create UML diagrams of the interface, 2 classes and driver program. Submit as a PDF along with the code. Sample Output: Enter the number you want to find the Fibonacci Series for: 10 Fib of 10 by iteration is: 55 Fib of 10 by formula is: 55

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

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

More Books

Students also viewed these Databases questions