CSE373—Data Structures and Algorithms for Nonmajors

Programming Assignment #1

due: Friday, 1/18/08, 10:00 PM

Introduction:

The int primitive in Java is a fixed size of 32 bits, going from -2147483648 to 2147483647.  If arithmetic goes outside the range, the numbers will wrap around (overflow).

The BigNum class can have an arbitrary number of digits, giving it an unlimited range.  It uses a List to represent the digits because the List can grow unboundedly.

To compile the code on the command line,

javac –cp junit.jar;. BigNum.java BigNumDemo.java BigNumTest.java

To run the simple demo,

java BigNumDemo

To run the tests,

java –cp junit.jar;. junit.textui.TestRunner BigNumTest

(on a Mac or Linux, change the ; to : )

Programming (60 points):

You should use good style, whitespace, naming conventions, etc., and comment your code.

1) Complete the BigNum class (look at other code in the class for guidance)

            a. Write the code for the public multiply method

            b. Write the code for the private subtractSmallerFromBigger method, using iterators

            c. Complete the toString method to partition the printed number with commas

            d. Write the code for the .equals method   

            (you are not allowed to change anything else inside the class)

2) Write JUnit tests for BigNum in BigNumTest.java

            a. Write unit tests for addition

            b. Write unit tests for subtraction

            c. Write unit tests for multiplication

            d. Write unit tests for .equals

Turn in your work electronically from the “assignments” link on the class webpage.