CSSE 220: Object Oriented Software Development
BigRational

You will do parts of this exercise by yourself, parts with group members, and parts via pair programming. In any case, be quick to ask questions of your instructor, student assistants and classmates as desired.

Consider: When you see “Consider” in red, where do you go to report your answer to that question?
Consider: When you see “Consider” in red, do you go to the Angel report to answer that question right at that time or do you wait until you have done the rest of the exercise?
Consider: When you see “Consider” in red, at that point do you answer only the single question in that “Consider” or all the questions in the Angel report?

Goals

Solidify your understanding of:

  1. How to implement a class:

    • The process for doing so:
      • Writing documented stubs before coding
      • Writing unit tests before coding
      • Using iterative enhancement
    • Implementing an interface
    • Writing constructors
    • Writing methods
    • Using fields
  2. Using objects:

    • Constructing objects with the new operator
    • Invoking methods on objects with the dot notation
    • Reading and applying the API (Application Programming Interface) for a class

  3. Java generics
  4. The Comparable interface
  5. The Object class and when its methods should be overridden

Grading rubric

  • 10 points: Did you produce documented stubs?
  • 35 points: Did your group produce a good set of test cases?
  • 55 points: Are your 11 constructors/methods correct?
Total: 100 points

Additionally, your score is reduced by up to 1/2 if your code:

  • Lacks correct documentation.
  • Disobeys our code conventions.

Finally, recall that this is a learning exercise, not a test. Hence, we will grade the “first draft” of your tests/code and then you may submit a second draft with errors corrected.

  • But don't abuse this privilege; strive to get it right in the first draft.

The Exercise - Overview

You will design, implement and test a BigRational class that:

In particular, it:

You will use this process drawn from Extreme Programming Rules and Practices:

    Instructions, Step 1: Add documented stubs

  1. Get the BigRational project, as follows:

    1. Unzip this BigRational.zip file, putting it into your JavaProjects folder.
    2. In Eclipse, choose File ~ Import and import the unzipped BigRational project.
    3. Add your BigRational project to your individual repository for this course.
  2. Examine the ArithmeticObject and Comparable interfaces. In the next step, you will write a BigRational class that implements these interfaces.
    Consider: How do the ArithmeticObject and Comparable interfaces impact what you must do in your BigRational class?
  3. Add a BigRational class to your project, and have it implement two interfaces, ArithmeticObject<BigRational> and Comparable<BigRational>, with only stubs for them at this time.
  4. Generate the Javadoc for the project. Examine the BigRational.html file, noting that Eclipse provided documentation for BigRational's methods for you (from the documentation for the interfaces).
  5. Java interfaces do not specify constructors, because constructors are more closely related to the implementation than to the specification.
    Consider: What constructor(s) do you think that your BigRational class should   have? Explain.
    Consider: When should those constructors throw an Exception?
  6. Add documented stubs for the two constructors listed in our answer to the previous question, where:
  7. Interfaces do not specify fields, because fields are part of the implementation, not the specification.
    Consider: What field(s) do you think that your BigRational class should   have? Explain.
  8. Examine the Java API specification for the Object class.
    Consider: Which of the Object methods do you think that your BigRational class should   override? Explain.
  9. Add documented stubs for the two methods listed in our answer to the previous question.
  10. Your equals method overrides the equals method in Object. If you look at the equals method in Object, you will see that it has an Object as its formal parameter.

    As such, your overriding equals method MUST have an Object (and NOT a BigRational) as its formal parameter.

    Consider:

    If your equals method is given an actual argument that is a BigRational, it should proceed as you would expect, testing for equality.

    But suppose that your equals method is given an actual argument that is NOT   a BigRational. What do you think that your equals method should   do? Explain.

  11. Sanity check:
    You should now have documented stubs for TWO constructors and NINE methods. If not, get help now.

    Commit your project to your indvidual repository at this point.

  12. Instructions, Step 2 - Write JUnit tests

  13. Add a new JUnit test case class for your BigRational class, noting:
  14. Your instructor will help you get into groups of three or four. With your group, quickly develop on paper (NOT in Eclipse) a good set of test cases for each of the 11 methods/constructors, noting:
  15. After your group has sketched test cases for all 11 methods/constructors, return to individual work: In Eclipse, implement the methods/constructors assigned to you per the above table.
  16. Commit your project to your indvidual repository when you have completed implementing your test cases.
  17. Step 3: Implement and test/debug

  18. Examine the Java API specification for the BigInteger class.
    Consider: What BigInteger method will you use to implement BigRational's abs method? Why?
    Consider: Since BigRational deals with fractions, reducing to lowest terms is relevant. What BigInteger method will you use to reduce to lowest terms? Why?
  19. Implement and test/debug your constructors and methods, one by one (thus using iterative enhancement). Use pair programming; switch roles (driver to observer, observer to driver) after each constructor/method, but stay on the same computer. Work through the constructors/methods in the following order, and each can assume that previously tested constructors/methods are correct:

    1. constructors
    2. toString
      Consider: The toString method must display the BigRational in lowest terms (e.g. 2 / 3 instead of 4 / 6). You have two choices: reduce to lowest terms when you construct the BigRational or each time toString is run. Which is more efficient? Why?
    3. compareTo
    4. equals
    5. Implement and test/debug the remaining methods in whatever order you choose.

  20. Before you leave class, make sure that both partners have a copy of the project.
  21. Complete the implementation as homework (individually, no longer pair programming).
  22. Make sure that your project has correct style. Make sure that there is appropriate HTML documentation for all your public methods (inheriting the documentation from the interfaces is fine).
  23. Commit your BigRational project to your individual repository from which you checked it out.