Description for Assignment #1

Problem Statement

We are required to create a class to represent polynomials of the following form:
anxn + . . . a2x2 + a1x + a0
The Polynomial class is able to receive data from outside and construct polynomial objects. It also have some mathematical operation functions: addition of two polynomials, subtraction of two polynomials and multiplication of a Polynomial by a constant. Notice that addition or subtraction can change the degree of resulting polynomials.

Algorithm and Overview of the Program

The program is a simple one. I used the algorithm from the assignment requirement for addition, subtraction and multiplication by constant. My program was designed to enable mathematical operations of two polynomials with different degrees.It can also check the result of mathematical operations and return the appropriate polynomial. The whole program is composed of two classes: class Polynomial and class testPolynomial.

The Polynomial Class

Polynomial had two instance variables to store the degree of a polynomial and the array of coefficients respectively. The number of coefficient is decided by the degree of the polynomial

One private method is provided to perform addition or subtraction operations of coefficients of two polynomials. I put addition and subtraction in one method because they are basically the same operation and mostly are handled in the same way.

Two constructor methods are provided according to the assignment requirement. one receives parameters to initialize an object with degree and coefficients. Another takes no arguments and initializes the polynomial to 0 to represent the 0 polynomial.

The class also has following public methods.


The testPolynomial Class

testPolynomial class is the test program for Polynomial class. It has two methods:


To see my source code, please go to my directory. There are two source files, one is Polynomial.java for the Polynomial class; One is testPolynomial.java for testPolynomial class.

The running result of the program is stored in testPolynomial.run.

Please send me an email Here if you have any questions.