On this page:
1 Introduction
2 What to do
3 Hints:   How to tackle the assignment
4 Criteria for grading
5 What to submit

Assignment 4: Using Lists

1 Introduction

A polynomial is made of several terms, each term having a coefficient and a variable raised to a power. Polynomials are one-variable if all their terms contain only one variable. An example of such a polynomial is \(f(x)=3x^4-5x^3+2x-4\). This polynomial has four terms.

The degree of a polynomial is defined as the highest power of the variable in a term. In the above example, the degree of the polynomial is 4. The polynomials we deal with have only positive, integral powers. The coefficients of our polynomials are also integral numbers.

Two polynomials are the same if they contain the same terms.

Several algebraic operations are possible with polynomials. The simplest one is evaluating the polynomial for a specific value of the variable. For example, for a polynomial \(f(x)=3x^4-5x^3+2x-4\), its value at \(x=2.5\) is defined as \(f(2.5)=3*(2.5)^4-5*(2.5)^3+2*(2.5)-4\) which is \(40.0625\).

Polynomials can be added together to create a new polynomial. The addition is performed by combining all the terms and adding the coefficients of the terms with the same power. For example \(3x^4-5x^3+2x-4\) + \(2x^3+2x^2+4\) = \(3x^4-3x^3+2x^2+2x\). The degree of the sum is the maximum of the degrees of the two polynomials.

2 What to do

Design an interface Polynomial that defines the above operations. This is your polynomial abstract data type. Specifically this interface should have the following method signatures:

Now implement this interface in a class PolynomialImpl. Beyond implementing the Polynomial interface, this implementation should have the following features/obey these constraints:

Write tests that thoroughly test this implementation. As always, it is recommended to write the test before completing the PolynomialImpl implementation.

3 Hints: How to tackle the assignment

Start by creating empty interfaces and classes for polynomials and nodes. Now select a method from the ADT and implement it end-to-end. Write tests for it before writing the implementation, and when your implementation passes your tests, move on to the next method. Tackle the parsing constructor at the end: you should not need it to test other methods.

For the add method: think about how you can “accumulate” the result. This is just a hint: you do not need to implement it this way.

4 Criteria for grading

You will be graded on:
  1. The design of your interface.

  2. Whether your implementation obeys all the above constraints.

  3. The correctness of your methods.

  4. How well you have tested your methods.

  5. Whether you have written enough comments for your classes and methods, and whether they are in proper Javadoc style.

  6. Whether you have used access modifiers correctly: public, protected or private.

  7. Whether your code is formatted correctly (according to the style grader).

5 What to submit

Submit a single zip file that has two folders: src and test. The src folder should contain all your .java files and the test should contain all your JUnit test files. Please submit your zip file by the above deadline, and then complete the self-evaluation until the day after the deadline.