CS0401 COE0401 Intermediate Java Programming
Summer 2007
Project 3-Fibonnacci application
Due date: July 31, 2007 11:59 PM
Late Due date: Aug 1, 2007 11:59 PM
Description:
Design and implement a Java application that allows the user to enter a number N. It returns to the user the result of the CS401 Fibonacci of N.
The objectives of this project are:
Ø to learn how to use recursion
Ø to learn how to create and use exceptions
The CS401 Fibonacci of a number N is calculated as follows:
F ( N ) = F ( N – 1 ) + F ( N – 3 )
F ( 2 ) = 1
F ( 1 ) = 1
F ( 0 ) = 0
Note that the above definition is different from the classical mathematical definition of the Fibonacci series.
For example if N = 7:
F ( 7 ) = F ( 6 ) + F ( 4 )
F ( 6 ) = F ( 5 ) + F ( 3 )
F ( 5 ) = F ( 4 ) + F ( 2 )
F ( 4 ) = F ( 3 ) + F ( 1 )
F ( 3 ) = F ( 2 ) + F ( 0 ) = 1 since F ( 2 ) = 1 and F ( 1 ) = 1
Thus, F ( 4 ) = 2 , F ( 5 ) = 3 & F ( 6 ) = 4
Consequently F ( 7 )= 6
Requirements
Your program(s) should have the following:
· An exception class called FibException that is thrown when the user enters a negative value of N.
· A method called F that takes in an integer N and returns the Fibonacci of N. It throws FibException if N < 0. This method is a recursive method that uses the above definitions to calculate the Fibonacci of N.
User Interface
Create a simple user interface such as the following:
Your user interface has to handle the following cases:
- When the user enters text that cannot be parsed into an integer. ( Hint: Use NumberFormatException). Your program should display the following:
- When the user enters a negative number, your program should display the following:
Grading
Programming style: 15 pts
Variable naming, program readability, comments
Functionality
Fibonacci method 25 pts
FibException 20 pts
Handling improper user input 20 pts
Appearance 10 pts
The user interface is nice and easy to use
Compiles without errors 10 pts
Extra Credits 10 pts
You can implement the mathematical Fibonacci series and add a button for the user to use to calculate the real Fibonacci function.