Polynomial3

Polynomial3 - / a sample polynomial class, with a main()...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
// a sample polynomial class, with a main() for testing public class Polynomial3 { private LinkedList lst; private int numTerms; private int degree; Polynomial3() { lst = new LinkedList(); numTerms = 0; degree = 0; } public LinkedList getList() { return lst; } public int getDegree() { return degree; } public int getTermNum() { return numTerms; } public void setDegree(int d) { degree = d; } public void setTermNum(int t) { numTerms = t; } // print a poly object in a readable format public void printPoly() { if (lst.isEmpty()) { System.out.print("numTerms = " + numTerms + "; degree = " + degree + "; "); System.out.println("F(x) = 0"); } else { System.out.print("numTerms = " + numTerms + "; degree = " + degree + "; " + "F(x) = "); Term tm = new Term(); int exponent; int coefficient; LinkedListItr itr = lst.first(); tm = (Term)(itr.retrieve());
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
exponent = tm.getExponent(); coefficient = tm.getCoefficient(); System.out.print(coefficient + "x^" + exponent); itr.advance(); for(; !itr.isPastEnd(); itr.advance())
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

Polynomial3 - / a sample polynomial class, with a main()...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online