// class that provides a Poly with Alphas as coeffecients import java.awt.*; public class AlphaPoly extends Poly { AlphaPoly(int degree) { super(degree, new Alpha(Integer.MIN_VALUE)); } AlphaPoly(int degree, Alpha[] coeffs) { super(degree, coeffs, new Alpha(Integer.MIN_VALUE)); } // creates a zero-polynomial w/ one nonzero coeff: onecoeff at position AlphaPoly(Alpha onecoeff, int position) { super(position, new Alpha(Integer.MIN_VALUE)); this.set(onecoeff, position); } // ----------------------- public void printPoly(TextArea text) { boolean plusflag = false; for (int j=0; j <= this.degree; j++) { if ((j==0) && (!(((Alpha)coeffs[j]).isZero()))) { plusflag = true; ((Alpha)(coeffs[j])).print(text); } else if (!(((Alpha)coeffs[j]).isZero())) { if (plusflag) text.append(" + "); ((Alpha)(coeffs[j])).print(text); 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(((Alpha)coeffs[j]).getPower(), 16); nums += (new Character(ch[j])).toString(); } return nums; } //--------------------------- public Poly shiftRight(int shval) { AlphaPoly newp = new AlphaPoly(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 Alpha(Integer.MIN_VALUE), j); return newp; } }