CSSE 221: Fundamentals of Software Development Honors
BigRational
Work on this exercise by yourself,
but
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?
- Hint: You go to the report
for the exercise,
located in Angel ~ Lessons ~ Assessment ~ Project Reports.
Go to Angel now and report your answer to this 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
The goals of this exercise are to apply and hence reinforce your understanding of:
- Important software engineering principles including:
- Writing to a specification (implementing an interface)
- Implementing by using documented stubs
- Implementing by using iterative enhancement
- Unit testing
- Java generics
- The Object class and when its methods should be overridden
The Exercise - Overview
You will design, implement and test a BigRational class that:
Instructions, Part 1 - Checkout the Project
- Open Eclipse.
- Checkout your BigRational project.
- You can look at the JavaEyes instructions
to remind yourself how to checkout a project
from your individual repository for this course.
Checking out BigRational is just like checking out JavaEyes
except that the project name is BigRational instead of JavaEyes.
Instructions, Part 2 - Implementing to an interface, with documented stubs
- 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?
- Add a BigRational class to your project.
- You can look at the JavaEyes instructions
to remind yourself how to add a class to a project.
- As usual, fill in the auto-generated Javadoc for the class description now.
- Have BigRational implement two interfaces,
ArithmeticObject<BigRational> and Comparable<BigRational>,
with only stubs for them at this time.
- Important: Use Quick Fix
to add the unimplemented methods for you!
You should NOT type in the methods yourself! Get help as needed!
- 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).
Instructions, Part 3 - Continuing the specification/design of BigRational
- Java interfaces do not specify constructors.
Consider:
Why not? What constructor(s) do you think that your BigRational class should have? Explain.
- Add documented stubs for the two constructors listed in our answer to the previous question.
- Interfaces do not specify fields.
Consider:
Why not? What field(s) do you think that your BigRational class should have? Explain.
- 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.
- Add documented stubs for the two methods listed in our answer to the previous question.
You should now have stubs for two constructors and nine methods. If not, get help now.
- 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?
Instructions, Part 4 - Generate JUnit test stubs
- Generate JUnit test stubs for the eight methods of BigRational.
Instructions, Part 5 - Use test-driven software development
- Implement and test your BigRational class, as follows:
- Step 0: Implement your constructors.
- You can't really test anything until you have at least one of your constructors.
- Step 1: Choose a method.
- Do equals first,
since JUnit tests for the other methods
may require equals to be correct.
Consider:
Why
will JUnit tests for the other methods
probably require that equals be correct?
- Do easier methods before harder ones.
- Save divide for last.
- Step 2: Implement unit tests for that method.
- Also write and implement unit tests for the class as implemented so far.
Note that you MUST write the tests for each method
before you write the code for that method.
No credit for this project
if you do not follow this test-driven software development methodology.
Part of the grade for this project is based on the quality of your unit tests.
Commit your project every time you complete Step 2,
so that we can check your methodology if we choose to.
- You can look at the JavaEyes instructions
to remind yourself how to commit a project
to the repository from which it was checked out.
- Step 3: Implement the method.
- Eliminate compile-time errors but do no testing yet.
- Step 4: Test the method.
- Run the test cases that you wrote for this method.
- Modify the implementation and/or test cases as needed
until the implementation passes all tests
and you are convinced that your code for this method and the class so far is correct.
- Step 5: Go back to Step 1 and do another method, until the entire class is complete.
Instructions, Part 6 - Turn in your work (i.e., commit your project)
- 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).
- Commit your BigRational project to the repository from which you checked it out.
- You can look at the JavaEyes instructions
to remind yourself how to commit a project
to the repository from which it was checked out.