Fibonacci Sequence as a Base for Representing Numbers (due 30 July 2014)

The Fibonacci series is obtained by starting with 0 and 1 and then adding the last two numbers to get the next one. Here are some terms in the Fibonacci series:

Fibonacci Sequence
n 0 1 2 3 4 5 6 7 8 9 10
Fib(n) 0 1 1 2 3 5 8 13 21 34 55

There are many applications of the Fibonacci series both in mathematics and in the real world. For example, we can express any given positive number as the sum of the terms in a Fibonacci sequence, taking the terms without repetition. For a unique representation, you may not take two successive terms in the Fibonacci series. For example, 29 = 21 + 8 or 53 = 34 + 13 + 5 + 1.

We can have a binary representation of the terms that we use in the Fibonacci series for the sum. In this representation, we use 1 if we accept the term in our sum and 0 if we do not.

Fib Series 34 21 13 8 5 3 2 1
53 = 1 0 1 0 1 0 0 1

There are several things to note in our representation. Our Fibonacci series starts at 1, we ignore the second 1. There are no leading zeros in our representation nor are there are consecutive 1's. The output will be of the form DECIMAL_NUM = BINARY_NUM_IN_FIB_BASE (fib), e.g. 53 = 10101001 (fib).

You will be writing one class FibonacciBase. In this class, you will have a method called convert() that takes as input a decimal integer and returns a String representation of the binary number in the Fibonacci base. You may have other helper methods in this class. In the method main() you will prompt the user to enter a decimal integer less than one million. Check if it is a positive integer less than one million and if it is, then convert the number to the binary String and then write out the result. You may NOT generate the numbers in the Fibonacci series with recursion. Here is the skeleton of the code

import java.util.Scanner;

class FibonacciBase
{
  // Convert from decimal number to binary string in Fib base
  public String convert (int num)
  {

  }

  public static void main (String[] args)
  {
    // Create Scanner object

    // Prompt user to enter a decimal integer

    // Test if the input is a decimal integer 
    // If not print error message and exit program

    // Get the String representation of the decimal number

    // Print out the result
  }
}

Here are some sample outputs that you can use to test your code:

13 = 100000 (fib)
17 = 100101 (fib)
29 = 1010000 (fib)
47 = 10100000 (fib)

We will be looking at good documentation, descriptive variable names, and adherence to the coding convention mentioned below. Your file FibonacciBas.java will have the following header:

/*
  File: FibonacciBase.java

  Description:

  Student Name:

  Student UT EID:

  Course Name: CS 312

  Unique Number: 

  Date Created:

  Date Last Modified:

*/

There is a modification that I would like to make to the standard coding conventions. Please align the opening and closing braces vertically so that you can easily make out the blocks of code. For example:

Do this:
if ( x > 5 )
{
  a = b + c;
}

Not this:
if ( x > 5 ) {
  a = b + c;
}

Use the turnin program to submit your .java file. We should receive your work by 11 PM on Wednesday, 30 Jul 2014. There will be substantial penalties if you do not adhere to the guidelines.