- 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!
- In the big, mostly empty pane at the left, right click and choose New ... Repository location.
- (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.
- 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.
- Click the + sign by the repository name to show the contents,
then right-click the BigRational project and choose Checkout.
-
Check the "Check out as a project in the workspace" radio button, and then
the Finish button.
- Switch back to the Java perspective.
- Look at the ArithmeticObject.java file
ArithmeticObject.java and ArithmeticObject.html.
- Create a new class called BigRational. In the New Java Class
dialog:
- Click "Add..." to add a new interface; type the first part of Comparable,
select Comparable. Press the Add button. Be sure that the
"Inherit Abstract Methods" is checked, and choose OK.
- Repeat this process to add in the ArithmeticObject interface also. Choose Finish.
- 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.
- 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?
- Make sure all of your doc comments are complete.
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.
- 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.]
- 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)
- 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!)
- Interfaces do not specify fields. Why not?
Consider: what fields(s) the BigRational class should have?
- 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)
- 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()).
- 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.
- 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!).
- Generate the javadoc again and make sure it is still complete.
Instructions Part 5 - Throw exceptions where necessary
- 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.