import java.util.ArrayList; /* BigInt.java ** Author: R. McCloskey and < YOUR NAME > ** Date: March 2019 ** CMPS 144 Prog. Assg. #3 ** ** Collaborated with: ... ** Known defects: ... ** ** An instance of this class represents an immutable integer. The usual ** arithmetic (sum, difference, product, quotient, remainder) and relational ** operations (less/greater/equal) are supported. ** ** What makes this class interesting is that there is no fixed upper bound ** upon the magnitude of the value that an instance of the class can represent, ** making it unlike any primitive data type used for representing integers ** (i.e., byte, short, int and long) and unlike the corresponding "wrapper" ** classes (java.lang.Integer, etc.) */ public class BigInt implements Comparable, Cloneable { // class constants // --------------- public final static BigInt ZERO = new BigInt("0"); public final static BigInt ONE = new BigInt("1"); public static final char PLUS = '+'; public static final char MINUS = '-'; // instance variables // ------------------ protected BigIntUnsigned magnitude; protected boolean isNegative; // constructors // ------------ /* Initializes this object so that it represents the integer described ** by the given string, which is assumed to be a decimal numeral ** (meaning that it begins with an optional sign (either '+' or '-') ** and each of its remaining characters is in the range '0'..'9'). */ public BigInt(String digitStr) { // STUB!! } /* Initializes this big integer so that it represents the given value of ** type int. */ public BigInt(int num) { this(num + ""); } /* Initializes this big integer so that it represents the number whose ** magnitude is specified by the first parameter and whose sign is ** indicated by the second. */ protected BigInt(BigIntUnsigned mag, char sign) { this.magnitude = mag; if (sign == PLUS || sign == MINUS) { this.isNegative = (sign == MINUS) && (!mag.equals(BigIntUnsigned.ZERO)); } else { throw new IllegalArgumentException("Invalid sign"); } } /* Initializes this big integer so that it represents the number whose ** magnitude is indicated by the first parameter and whose sign is ** indicated by the second. */ protected BigInt(BigIntUnsigned mag, boolean isNeg) { this.magnitude = mag; this.isNegative = isNeg; } // observers // --------- /* Returns the decimal numeral corresponding to this object's value. ** E.g., if this object represents 5689, the string returned should be ** "5689". A leading zero should appear only if the object represents ** zero. */ public String toString() { return ""; // STUB! } /* Returns a negative value, zero, or a positive value, respectively, ** according to whether the integer represented by this object is ** less than, equal to, or greater than, respectively, the integer ** represented by the other object. */ public int compareTo(BigInt other) { return 0; // STUB! } /* Reports whether or not this object is equal to the other one. That is ** the case if and only if the other object, too, is an instance of this ** class and the two objects represent the same integer value. */ public boolean equals(Object other) { return (other instanceof BigInt) && this.compareTo((BigInt)other) == 0; } /* Reports whether or not this object represents an integer that is ** less than that represented by the other object. */ public boolean isLessThan(BigInt other) { return this.compareTo(other) < 0; } /* Reports whether or not this object represents an integer that is ** greater than that represented by the other object. */ public boolean isGreaterThan(BigInt other) { return this.compareTo(other) > 0; } // generators // ---------- /* Returns a new instance of this class that represents the ** absolute value of the integer represented by this object. */ public BigInt abs() { return this; // STUB!! } /* Returns a new instance of this class that represents the sum of ** this object and the other one (i.e., this one plus the other one) */ public BigInt plus(BigInt other) { return ZERO; // STUB!! } /* Returns a new instance of this class that represents the difference ** of this object and the other one (i.e., this one minus the other one). */ public BigInt minus(BigInt other) { return ZERO; // STUB!! } /* Returns a new instance of this class that represents the product of ** this object and the other one (i.e., this one times the other one). */ public BigInt times(BigInt other) { return ONE; // STUB!! } /* Returns a new instance of this class that represents the integer ** quotient resulting from dividing this object by the other one. ** pre: !other.equals(ZERO) */ public BigInt dividedBy(BigInt other) { return ONE; // STUB!! } /* Returns a new instance of this class that represents the remainder ** resulting from dividing this object by the other one. ** pre: !other.equals(ZERO) */ public BigInt mod(BigInt other) { return ZERO; // STUB!! } }