Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The book name is Java An introduction to problem sloving 7ed Plz give the code in java and it match with the prof output below.

The book name is Java An introduction to problem sloving 7ed

Plz give the code in java and it match with the prof output below. Plz provide your output too.

The Assignment:

Chapter 11:

Programming Projects 3: This project is found starting on page 861.

Assignment Guidelines:

The Fibonacci sequence occurs frequently in nature as the growth rate for certain idealized animal populations. The sequence begins with 0 and 1, and each successive Fibonacci number is the sum of the two previous Fibonacci numbers. Hence, the first ten Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, and 34. The third number in the series is 0 + 1, which is 1; the fourth number is 1 + 1, which is 2; the fifth number is 1 + 2, which is 3; and so on.

Besides describing population growth, the sequence can be used to define the form of a spiral. In addition, the ratios of successive Fibonacci numbers in the sequence approach a constant, approximately 1.618, called the golden mean. Humans find this ratio so aesthetically pleasing that it is often used to select the length and width ratios of rooms and postcards.

Use a recursive formula to define a static method to compute the nth Fibonacci number, given n as an argument. Your method should not use a loop to compute all the Fibonacci numbers up to the desired one, but should be a simple recursive method. Place this static recursive method in a program that demonstrates how the ratio of Fibonacci numbers converges. Your program will ask the user to specify how many Fibonacci numbers it should calculate. It will then display the Fibonacci numbers, one per line. After the first two lines, it will also display the ratio of the current and previous Fibonacci numbers on each line. (The initial ratios do not make sense.) The output should look something like the following if the user enters

5:

Fibonacci #1 = 0

Fibonacci #2 = 1

Fibonacci #3 = 1; 1/1 = 1

Fibonacci #4 = 2; 2/1 = 2

Fibonacci #5 = 3; 3/2 = 1.5

Notes:

The recursive algorithm for Fibonacci numbers is a little more involved than the series calculations in the previous Projects. Base cases for 0, 1 or two numbers simply return a value, and all other numbers make two recursive calls to get the previous two Fibonacci numbers to add together to obtain the current number. The method to calculate a Fibonacci number is recursive, but the code to print the output is not; it uses a for-loop to cycle through the Fibonacci numbers and ratios.

Note:

The assignment must have the following classes:

1. fibonacci, in file fibonacci.java

2.fibonacciDemo, in file fibonacciDemo.java

Sample Run:

----jGRASP exec: java Fibonacci How many Fibonacci numbers do you want to use? Enter a positive integer: 25 Here is the Fibonacci series and ratio of current number to previous number for 25 Fibonacci numbers: Fibonacci #1 = 0 Fibonacci #2 = 1 Fibonacci #3 = 1 and ratio = 1/1 = 1.0 Fibonacci #4 = 2 and ratio = 2/1 = 2.0 Fibonacci #5 = 3 and ratio = 3/2 = 1.5 Fibonacci #6 = 5 and ratio = 5/3 = 1.6666666 Fibonacci #7 = 8 and ratio = 8/5 = 1.6 Fibonacci #8 = 13 and ratio = 13/8 = 1.625 Fibonacci #9 = 21 and ratio = 21/13 = 1.6153846 Fibonacci #10 = 34 and ratio = 34/21 = 1.6190476 Fibonacci #11 = 55 and ratio = 55/34 = 1.617647 Fibonacci #12 = 89 and ratio = 89/55 = 1.6181818 Fibonacci #13 = 144 and ratio = 144/89 = 1.6179775 Fibonacci #14 = 233 and ratio = 233/144 = 1.6180556 Fibonacci #15 = 377 and ratio = 377/233 = 1.6180258 Fibonacci #16 = 610 and ratio = 610/377 = 1.6180371 Fibonacci #17 = 987 and ratio = 987/610 = 1.6180328 Fibonacci #18 = 1597 and ratio = 1597/987 = 1.6180345 Fibonacci #19 = 2584 and ratio = 2584/1597 = 1.6180338 Fibonacci #20 = 4181 and ratio = 4181/2584 = 1.618034 Fibonacci #21 = 6765 and ratio = 6765/4181 = 1.618034 Fibonacci #22 = 10946 and ratio = 10946/6765 = 1.618034 Fibonacci #23 = 17711 and ratio = 17711/10946 = 1.618034 Fibonacci #24 = 28657 and ratio = 28657/17711 = 1.618034 Fibonacci #25 = 46368 and ratio = 46368/28657 = 1.618034 Do again? Enter 'y' for yes. n ----jGRASP: operation complete.

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

What is operatiing system?

Answered: 1 week ago