// class that provides a Poly with Binary Coeffs import java.awt.*; public class BinaryPoly extends Poly { // set type of poly to integer BinaryPoly(int degree) { super(degree, new Integer(0)); } BinaryPoly(int degree, Integer[] coeffs) { super(degree, coeffs, new Integer(0)); } // ----------------------- public void printPoly(TextArea text) { boolean plusflag = false; for (int j=0; j <= this.degree; j++) { if ((j==0) && (((Integer)coeffs[j]).intValue()!=0)) { plusflag = true; text.append("1"); } else if (((Integer)coeffs[j]).intValue()!=0) { if (plusflag) text.append(" + "); text.append("x^" + j); plusflag=true; } } if (!plusflag) // no polynomial printed text.append("Zero Polynomial"); text.append("\n"); } // ----------------------- public String getString() { char [] ch = new char[degree+1]; String nums = ""; for (int j=0; j <= degree; j++) { ch[j] = Character.forDigit(((Integer)coeffs[j]).intValue(), 2); nums += (new Character(ch[j])).toString(); } return nums; } public Poly shiftRight(int shval) { BinaryPoly newp = new BinaryPoly(degree+shval); for (int i=degree; i >= 0; i--) newp.set(coeffs[i], i+shval); for (int j=shval-1; j >= 0; j--) newp.set(new Integer(0), j); return newp; } }