File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes fibonacci program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "fibonacci program" Watch "fibonacci program" New topic

fibonacci program

Jessie Brown

Joined: Jun 19, 2009
Posts: 1
I have a program that i need to complete. I wrote the first one (FibonacciGenerator) with stated variables - everything worked fine
I now want to split it up so that the user can give a number and the program gives the correct number back. (ie, fib(5)=5 AND NOT fib(5)=2)
Please help as I know what i need to do but the how escapes me.

constructor portion

Test Program (I know i need to return the input to the constructor file but how??)

Any help is appreciated

Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 31070

Welcome to JavaRanch!

I don't really understand what you are asking. Your test program looks like it outputs the right number. Are you saying you want to move that logic to the Fibonacci class itself?

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Rob Spoor

Joined: Oct 27, 2005
Posts: 19785

Your Fibonacci class works, if you ignore the element 0. I've changed your test program a bit:
You'll need to check the logic of your tester. You skip nextNumber for 1 and 2, so it skips the calculation of fib(1) and fib(2).

How To Ask Questions How To Answer Questions
anandhi mohan

Joined: Mar 24, 2009
Posts: 9
try this code:

your n value should be starting from 1.
I agree. Here's the link:
subject: fibonacci program