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?
- 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?
GoalsSolidify your understanding of:
|
Grading rubric
Additionally, your score is reduced by up to 1/2 if your code:
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.
|
You will design, implement and test a BigRational class that:
74939393930003456 / 83838384550230300266666629999
You will use this process drawn from Extreme Programming Rules and Practices:
Consider: How do the ArithmeticObject and Comparable interfaces impact what you must do in your BigRational class?
Consider: What constructor(s) do you think that your BigRational class should have? Explain.
Consider: When should those constructors throw an Exception?
Consider: What field(s) do you think that your BigRational class should have? Explain.
Consider: Which of the Object methods do you think that your BigRational class should override? Explain.
-77 / 4 5 0
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.
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.
If your group has 3 members: | If your group has 4 members: | |||||
---|---|---|---|---|---|---|
Member 1 | Member 2 | Member 3 | Member 1 | Member 2 | Member 3 | Member 4 |
|
|
|
|
|
|
|
public void testBigRationalBigIntegerBigInteger() { try { new BigRational(new BigInteger("7"), new BigInteger("0")); fail("Constructor did not throw ArithmeticException when denominator was zero"); } catch (ArithmeticException exception) { // First test succeeded if it gets here } catch (Exception exception) { exception.printStackTrace(); fail("Constructor threw a " + exception.toString() + " when it should have thrown an ArithmeticException"); } try { new BigRational(new BigInteger("0"), new BigInteger("7")); // No Exception } catch (ArithmeticException exception) { fail("Contructor threw ArithmeticException when denominator was NOT zero"); } catch (Exception exception) { exception.printStackTrace(); fail("Constructor threw a " + exception.toString() + " when it should not have thrown any Exception"); } // Second test succeeded if it gets here }
Here is a link to some slides on Exceptions.
BigRational r = new BigRational("3", "4"); BigRational s = new BigRational("2", "3"); assertTrue(r.compareTo(s) > 0);
Here is a link to the documentation for the Assert 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?
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?