CMSI 281
Homework #2

If you did not finish the reading assignment for the first homework assignment, finish it for this assignment. (It was [Gray], Chapters 0, 1, and Chapter 2 up through 2.2 only.) and [Bloch], items 1-5, 7-9, 13, and 31. The new reading for this assignment is [Bloch], items 17, 23-25, 27, and 39.

Submit answers to the following problems, in a nicely typeset pdf file:

  1. Write a Java interface for (single-variable) polynomials whose coefficients are of type double and whose exponents are of type int and non-negative. Include methods to
  2. Write an array-based implementation of the polynomial interface from the previous problem. Polynomials should be represented in an array of doubles, indexed by exponent.
  3. Give a UML diagram for the interface and class specified in the previous two problems.
  4. Write a comprehensive unit test for your array-based polynomial class.
  5. Write a class for rational numbers. Include methods to add, subtract, multiply and divide. Override equals, hashCode, and toString.
  6. Give a UML diagram for the rational numbers class.
  7. Write a comprehensive unit test for the rational numbers class.

You will be creating a document that contains numbered solutions to the problems, using LaTeX, OpenOffice, Word, or other document preparation system. If a particular problem asks for source code, you may embed the source in place in the document, or give the answer as "See <filename>" and place the source code at the end of the document. Compose the pdf with the solutions to each problem, numbered, and in order. You must submit a hard copy of the pdf and the source code in one packet of stapled together 8.5" × 11" sheets of paper. You must also make available source code in electronic form, either by emailing me a zip file containing the sources, or by providing me readonly access to a cvs or svn repository, where I can check out code by date.

Your sources should be organized as follows:

homework
  cmsi281
    src
      main
        docs
          hw2.tex (or .odt or .doc or ...)
          <diagram source files>, if any
          <images>, if any
        java
          edu
            lmu
              cs
                math
                  Polynomial.java (an interface)
                  ArrayPolynomial.java (implements Polynomial)
                  Rational.java (a class)
      test
        java
          edu
            lmu
              cs
                math
                  ArrayPolynomialTest.java  (JUnit test case)
                  RationalTest.java (JUnit test case)
Notes