/* * an interface that defines arbitrary-precision numbers * @author Biagioni, Edoardo * @assignment lecture 6 * @date January 30, 2008 */ import java.lang.ArithmeticException; public interface ArbitraryPrecisionInterface { /* all Objects have toString and equals methods. * It is expected that any class implementing this interface * will implement their own toString and equals method rather * than relying on the inherited methods. */ /* simple comparisons */ /* @return is this number zero? */ boolean isZero(); /* @return is this number odd? */ boolean isOdd(); /* @return is this number less than the parameter? */ boolean isLessThan(ArbitraryPrecisionInterface n); /* very simple arithmetic operations */ /* @return a number that is one greater than this number */ ArbitraryPrecisionInterface oneMore(); /* @return a number that is one less than this number */ ArbitraryPrecisionInterface oneLess() throws ArithmeticException; /* @return a number that is twice this number */ ArbitraryPrecisionInterface twice(); /* @return a number that is half this number */ ArbitraryPrecisionInterface half(); /* methods to perform the basic arithmetic operations, +, -, *, /, %. */ /* for example, with variables one, two and three, can do: * three = two.add(one); or * three = one.add(two); or * one = three.subtract(two); * with variables x and y, can do: * x = increaseBy(y); -- x is increased by the value of y * y = divideBy(y); -- x is decreased by the value of y */ /* @param a number to be added to this number * @return a third number, the sum of the parameter and this number */ ArbitraryPrecisionInterface add(ArbitraryPrecisionInterface n); /* @param a number to be subtracted from this number * @return the difference between this number and the parameter * @throws ArithmeticException if the result is negative */ ArbitraryPrecisionInterface subtract(ArbitraryPrecisionInterface n) throws ArithmeticException; /* @param a number to be multiplied to this number * @return the product of this number and the parameter */ ArbitraryPrecisionInterface multiply(ArbitraryPrecisionInterface n); /* @param the divisor * @return a third number, this number divided by the divisor * @throws ArithmeticException if the divisor is zero */ ArbitraryPrecisionInterface divide(ArbitraryPrecisionInterface divisor) throws ArithmeticException; /* @param the divisor * @return a third number, this remainder when dividing by the divisor * @throws ArithmeticException if the divisor is zero */ ArbitraryPrecisionInterface modulo(ArbitraryPrecisionInterface divisor) throws ArithmeticException; /* corresponding mutator methods for add, subtract, multiply, divide */ void addTo(ArbitraryPrecisionInterface n); void subtractFromTo(ArbitraryPrecisionInterface n); void multiplyBy(ArbitraryPrecisionInterface n); void divideBy(ArbitraryPrecisionInterface n) throws ArithmeticException; }