Reference no: EM132213391
Write a set of algorithms and programs to compute and create three tables for the Fibonacci numbers: one recursive, one ‘fast recursive', and one iterative.
Provide a FibDemo class that will produce the three tables of n Fibonacci numbers, three classes (FibSequence, FastFibSequence, and LoopFibSequence) that each implements the next() method as provided in a Sequence interface
The number of Fibonacci numbers to be provided in the tables (n) will be input from a file and the three tables themselves will be output to another file - both file names to be found on the command-line
The output file will contain one table of recursively-computed Fibonacci numbers; followed by a second table of "expected" values - using an iterative algorithm like LoopFib; followed by a third table of ‘fast' recursively-computed Fibonacci numbers. The output file name will be found on the command-line using the "java" compiler in linux.
All tables will be labeled, values right-aligned, "squarish", and obviously have identical values. Additionally, the execution time (in nanoseconds) to compute all of the values for each table will be printed/labeled, following each table, for comparison purposes
All output will be handled by the Demo or exception-handling classes.
The name of the input file and the output file will be found on the command-line. Input validation and exception handling are expected. All input will be handled by the Demo class. Instructions for compilation/execution should include command-line input details. The number of Fibonacci numbers in the tables will be determined by an integer value located in an input file, The integer value in the input file (n) will be a less than 40.
You must write at least six programs: one will be the Sequence interface with a next() method; three will be the FibSequence, FastFibSequence, and LoopFibSequence classes that will each implement the interface; one will be the FibDemo class that will perform the demonstration; one or more classes to handle user-defined exceptions; and perhaps a "table" class or other classes, as required.
The Sequence interface will provide for the next() method. Interface will use class documentation standards.
FibDemo will access the input (and output) files and read/validate the number of entries to be used for each table. A trio of separate loops will then be executed, requesting the next Fibonacci number the requisite number of times. System time, before and after each loop, will facilitate determining execution time for each table.
At a minimum, exceptions for File-Not-Found, Empty-File, Non-Integer-Input, and Invalid-Input (negative/zero, greater-than-maximum-value) will be handled for input/output. Invalid-Input will be a user-defined exception class
All files must be closed properly, even if there are exceptions (finally clause). User-defined exception class will use class documentation standards.
Each FibSequence class will implement its own next() method and any other methods/instance variables required to create the Fibonacci numbers.