FileDocCategorySizeDatePackage
FibonacciImpl.javaAPI DocExample993Sat Sep 09 21:21:40 BST 2000None

FibonacciImpl

public class FibonacciImpl extends UnicastRemoteObject implements Fibonacci

Fields Summary
Constructors Summary
public FibonacciImpl()

    UnicastRemoteObject.exportObject(this);
  //  setLog(System.out);
  
Methods Summary
public java.math.BigIntegergetFibonacci(int n)

    
    return this.getFibonacci(new BigInteger(Long.toString(n)));  
    
  
public java.math.BigIntegergetFibonacci(java.math.BigInteger n)

  
    
    System.out.println("Calculating the " + n + "th Fibonacci number");
    BigInteger zero = new BigInteger("0");
    BigInteger one  = new BigInteger("1");
    
    if (n.equals(zero)) return zero;
    if (n.equals(one)) return one; 

    BigInteger i  = one;
    BigInteger a  = zero;
    BigInteger b  = one;

    while (i.compareTo(n) == -1) {
      BigInteger temp = b;
      b = b.add(a);
      a = temp; 
      i = i.add(one);
    }

    return b;