BigRational
Work on this exercise in pairs.
If there are an odd number of students in your section, you may ask the instructor to work alone. In general only one student will be permitted to do so—pair programming is a skill we want you to continue to develop.
Let your instructor know who you are working with on the project so that he can set up your project in Subversion.
Goals
The goals of this exercise are:
-
To apply important software engineering principles such as unit testing and writing to a specification.
-
To apply genericity via interfaces and introduce genericity of type parameters.
The Exercise
Design and implement a BigRational class that:
-
Implements this Rational interface
-
Implements the Comparable interface (that Rational extends)
-
Can input, store and process rationals of arbitrary length
-
With your instructor—either during work time in class or outside of class—discuss the design of your BigRational class. You should write down brief notes/questions on the following topics before you have this discussion:
-
Examine and discuss the Rational interface
-
How does the Rational interface impact what you must do in your BigRational class?
-
Examine and discuss the Comparable interface
-
In the javadocs, what does the
<T>
mean in the name of the interface?
-
What does the
T
mean in the signature of the compareTo(T o)
method?
-
How does the Comparable interface impact what you must do in your BigRational class?
-
Interfaces do not specify constructors
-
Why not?
-
What constructor(s) do you think that your BigRational class should have?
-
Interfaces do not specify fields
-
Why not?
-
What fields(s) do you think that your BigRational class should have?
-
Implement your BigRational class, as follows:
-
You may NOT change the Rational interface in any way.
-
Check out the BigRational project from the new Subversion repository created for this exercise. The repository URL is
http://svn.cs.rose-hulman.edu/repos/csse220-200730-
username1-
username2, substituting your usernames in alphabetical order.
-
Run the project as a JUnit test.
-
Modify the project so as to add test code for each of the methods you plan to implement.
-
Please show your test code to your instructor or an assistant before proceeding to the next step, i.e. the implementation of your methods.
-
Design, implement, and debug the methods as required by the interface. You will find the BigInteger class useful in your implementation.