CSC 132 Fall 2000
Lab 1
Due: end of lab period 7 September 2000
15 points
"Poly wants a ….?"
The eccentric download folder contains file called IntArrayPoly.java, which is a partially completed implementation of an ADT for polynomials, and IntPolyDriver.java which can be used to test it. As implied by the class name, polynomial coefficients will be integers and are stored in an array. This assignment is based on Chapter 3 Programming Project 8 on page 169 of the text.
A polynomial is an arithmetic expression of the form
a0 + a1x + a2x2 + a3x3 + … + akxk
The highest exponent, k, is called the degree of the polynomial, and the constants ai are the coefficients. Here is an example of a polynomial of degree five:
5 + 17x - 27x2 + 3x5
Notice that some terms can have coefficients of 0 (zero), in this case the x3 and x4 terms.
A polynomial can be represented in an array by storing the coefficient for the xi term in array element i. For the example above, array element 0 would hold 5, element 1 would hold 17, element 2 would hold -27, elements 3 and 4 would hold 0 and element 5 would hold 3.
The class has several methods whose specifications are given in the source code. You are to implement three of the methods, Evaluate, Sum, and Print. Specifications are:
/* Evaluate polynomial by substituting value for x. Returns result. */ public int Evaluate(int value) /* Produce third polynomial which is the sum of two existing ones. Maximum * degree is the greater of the two maximums. The coefficient for the xi term * will be the sum of the two coefficients for the xi terms of the two * existing polynomials. For example, the sum of 3+2x and 5-6x+7x3 is * 8-4x+7x3. */ public static IntArrayPoly Sum(IntArrayPoly first, IntArrayPoly second) /* Print polynomial. Uses '^' to represent exponentiation operator. Does * not print terms with coefficient of zero. If the first printed term has * positive coefficient, does not print the leading '+'. For all subsequent * terms, prints '+' or '-' as appropriate. For example, 8-4x+7x3 is printed * as 8-4x+7x^3, not 8+(-4x)+7x^3. */ public void Print()
Add comments that can be processed by javadoc into nice HTML documentation. When finished, submit IntArrayPoly.java to your upload folder.
[ Assignments | CSC 132 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 7 September 2000
Peter Sanderson (
PeteSanderson@smsu.edu )