title: BigInteger Conversion from int to BigInteger
body: <p>I'm having trouble working with BigIntegers. I'm having trouble with the <code>add</code> method in the Rational class. In the <code>Rational(int x, int y)</code> constructor I'm trying to convert the parameters datatype <code>int</code> into the instance variable datatype of <code>BigInteger</code> though the use of the<code>toString(int n)</code> method. <br/></p>
  
  <ol>
  <li>Am I doing the conversion correctly inside the <code>Rational(int x, int y)</code> constructor? </li>
  <li>They way the <code>add</code> method is written I'm getting an error under all of n.num and n.den. I don't understand why I'm getting that error. Am I not correctly using the <code>add</code> method from the BigInteger class? 
  <a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html" rel="nofollow">http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html</a>
  <br/><br/></li>
  </ol>
  
  <p>Suppose one class has the following</p>
  
  <pre><code>Rational a = new Rational(1,2);
  Rational b = new Rational(1,3);
  Rational c = new Rational(1,6);
  Rational sum = a.add(b).add(c);
  println(sum);
  </code></pre>
  
  <p>and the Rational class includes </p>
  
  <pre><code>import acm.program.*;
  import java.math.*;
  
  public class Rational{
  
      public Rational(int x, int y) {
          num = new BigInteger(toString(x));
          den = new BigInteger(toString(y));
      }
  
      public toString(int n) {
          return toString(n); 
      }
  
      public BigInteger add(BigInteger n) {
          return new BigInteger(this.num * n.den + n.num * this.den, this.den *  n.den)
      }
  
      /*  private instance variables  */
      private BigInteger num; 
      private BigInteger den;
  }
  </code></pre>