BigRational Programming Assignment

Work on this exercise by yourself, but ask questions of your instructor, student assistants and classmates as desired.

Goals

The goals of this exercise are to:

The Exercise

Instructions Part 1 - What is an API, Why do we have it, What can we do with it?

  1. Open the Java API description (You can also use the local copy on your computer.
  2. Navigate to the BigInteger class and look at all the information.
  3. Why is this class useful (i.e. why not just use "int"s?)
  4. Navigate to Comparable and figure out what it is all about.

What is an Interface?

  1. Does BigInteger need to have a compareTo( ) method? (why?....)
  2. Navigate back to BigInteger and find the compareTo( ) method. Notice that BigInteger implements the Comparable interface.
  3. Navigate to the ArithmeticObject interface. This interface is not part of the Java library - we created it.

Instructions Part 2 - Check out the project

  1. Open Eclipse, and go to the SVN Repository Browsing perspective.  To do this, click the Open Perspective button near the Top Right corner of the Eclipse window, choose Other, and then SVN Repository Exploring. Click OK Do not choose CVS Repository Exploring!
  2. In the big, mostly empty pane at the left, right click and choose New ... Repository location.
  3. (Do this step very carefully) When  asked for the URL, enter http://svn.cs.rose-hulman.edu/repos/csse220-200830-<username>, where you substitute your actual username for  <username>.  For example, George Bush would enter http://svn.cs.rose-hulman.edu/repos/csse220-200830-bushgw .  Be sure to not get any spaces at the beginning or end of the URL you enter.
  4. If you are asked for your password, enter your SVN password (usually 5 letters and three numbers), rather than your Kerberos password.  You may have to enter it more than once.  If it asks you more than 4 times, get help.
  5. Click the + sign by the repository name to show the contents, then right-click the BigRational project and choose Checkout.
  6. Check the "Check out as a project in the workspace" radio button, and then the Finish button. 
  7. Switch back to the Java perspective.
  8. Look at the ArithmeticObject.java file ArithmeticObject.java and ArithmeticObject.html.
  9. Create a new class called BigRational. In the New Java Class dialog:
  10. Generate the html documentation for your code by selecting your project in the Package Explorer and choosing Project → Generate Javadoc..., then select all the defaults. Note that you may have to browse into your Java installation bin directory to locate the javadoc.exe file.
  11. Look at the generated files, which will be in a new doc folder in your project (if they aren't there, repeat step 9 with help). Do you understand what happened?
  12. Make sure all of your doc comments are complete.
  13. Instructions Part 3 - Write the code and execute the project

    Commit your code to your SVN repository often . Then you will  have a backup of each phase of your work, and we will have a record of when you did various parts of the project). To commit, right-click on the project in Eclipse's Package Explorer,  and choose Team→Commit. Enter a brief comment that describes the changes to your code since the last commit.

    1. Note that since we are dealing with fractions, we should give all answers in lowest terms (reduced). ]Hint: a careful perusal of the BigInteger class could reveal a method that could save you some time here.]
    2. The interface provides a contract that you must follow. Implement each of the stubs. (A stub is a method with an empty body or a simple return statement, ready to be completed).
      • Note that these stubs each take an argument of type Object (following the general interface). You can't change the parameter to BigRational, because that will break the contract. Instead, you should typecast the input argument to BigRational (see the text for simple examples if need be; 1.4.4 gives a simple example with ints and doubles; examples with objects are found in 4.1.9 (page 106, for example)).
      • Note BigRationals are immutable; each math method should return a brand-new object, leaving the addends untouched (so it's like c = a + b, not like a += b)
    3. Interfaces do not specify constructors. Why not? Consider: what constructor(s) the BigRational class should have. (Note: you should have at least two constructors. If you aren't sure which, ask!)
    4. Interfaces do not specify fields. Why not? Consider: what fields(s) the BigRational class should have?
    5. Implement toString() and equals(). toString() should be simple (just display in the form a/b) but should display special cases intelligently: instead of printing 5/1, it should print 5, and 0/10 should be just 0. Please make sure you get this right, since my JUnit tests rely on your having a correct toString() method. Examples:
      • 2/3 (reduced instead of 4/6)
      • 4 (instead of 4/1)
      • -6/5 (negative in numerator instead of 6/-5)
      • 1/2 (no double neg, instead of -1/-2)
      • 0 (instead of 0/3)
    6. Add two additional methods to BigRational (not the interface) that enhance the capability of BigRational. Note that these cannot simply make visible any functions or data that already exist (for example, accessors or reduce()).
    7. Make sure that you have javadoc for any methods you wrote (it isn't needed for ones specified by the interface, since they already have javadoc).

    Instructions Part 4 - Add unit tests

    Actually, it would be good to develop unit tests in parallel with your development of the methods.  Test each method as soon as you write it, then commit the project to your repository.

    1. Create JUnit tests for each of your methods. Part of your grade will be based on how well you choose your test cases to convince us that your BigRational methods actually work (assuming that they do work!).
    2. Generate the javadoc again and make sure it is still complete.

    Instructions Part 5 - Throw exceptions where necessary

    1. Make sure that your code throws an ArithmeticException whenever you attempt to divide by zero (or to have zero as a denominator).  Can you include tests for this in your Unit Tests?  You may find JUnit's fail() method helpful here.