It sounds like you are confused about the BigInteger
constructors on the javadoc; the truth is, from what you say, you only need the one needed to convert int
to BigInteger
(through String)! You just need to change your constructors in Rational
to use BigInteger. If the Rational
constructors take in int
datatypes, simply convert them within the constructor to BigInteger
type and assign to your BigInteger
instance variables. If you look at the methods, there are equivalents to the basic operations you need (add, subtract, etc) for the other methods in the class.
EDIT: I'll give a small example. I assume your Rational(int x, int y)
constructor looks something like this:
public Rational (int x, int y) {
num = x;
dem = y;
}
If num
and den
are now BigIntegers, you'll need to change it so x and y are converted to BigIntegers. If you look at the BigInteger
constructors, there are none that take int directly. But we have BigInteger(String val)
, and int can be converted to String
.
public Rational (int x, int y) {
num = new BigInteger(Integer.toString(x));
dem = new BigInteger(Integer.toString(y));
}
With this idea you can figure out the rest on your own.