COMP 2100 Lab Exercise 5: Make a Difference
(10 points)
Turn in before the next lab session.

Introduction

For this exercise, you will extend the Polynomial class (Project 2) with a class having one method.
public static Polynomial difference(Polynomial a,
                                    Polynomial b)
	              throws IllegalArgumentException

Produces a new Polynomial which is the difference between the two argument polynomials. In other words, it is the result of subtracting the second polynomial from the first one.

Preconditions: a != null && b != null

Parameters:
    a - a polynomial
    b - a polynomial

Returns:
    a polynomial representing the difference of a and b

Throws:
    IllegalArgumentException - if either argument is null

This method provides the capability of subtracting one polynomial from another. For example if a is 2x2 - 4 and b is x2 + 3x - 3, then subtracting b from a yields x2 - 3x - 1

Details

To keep this exercise independent from Project 2, you will do the following:

  1. Download the zip file Ex5.zip and extract all. It sets up the Ex5 folder with three files:
  2. You will develop a new class called PolynomialEx5, which extends Polynomial. The difference() method will be the only method in the class. This class inherits the poly instance variable and all methods of the Polynomial class, so you can use them without restriction.
  3. You do not need to add any comments or Javadoc to your solution!
  4. Here are links to the Polynomial API and the Term API.
  5. If you do this cleverly, you will not need to use any Term class objects or methods.

Make life easier for yourself by defining subtraction in terms of existing Polynomial operations.

Scoring

PointsDescription
8Produces correct results
2 Clever design will be rewarded.

To Turn In

Drop your completed PolynomialEx5.java file into your DropBox.
[ COMP 2100 | Peter Sanderson | Math Sciences home page | Otterbein ]

Last updated: