Lab 5 - Fractions
- Open your homework in IntelliJ (or other IDE, so that it can
be changed), be sure that unit testing works.
- If you do not have the latest version of your work on
bitbucket (or github), create a commit and push it. If
necessary, refer to the materials of the first lab. The test
file LfractionTest.java must also be included in the
version control.
- The teacher will assign you a partner for this lab.
- If this is not already the case, express the method of
subtraction of fractions through adding the opposite (also
change the method of finding the opposite, if necessary). Also
express the method of division of fractions through multiplying
by the inverse (change the method of finding the inverse, if
necessary).
- If this is not already the case, reduce the fraction in the
constructor - every new fraction created is reduced and the sign
of the fraction is in the numerator. If necessary, add a static
method of finding the greatest common divisor, preferably by the
Euclidean algorithm.
- If this is not already the case, express the equals
method using the compareTo method (if necessary,
change the compareTo method, only integers may be used
for comparison).
- Divide the roles: developer and tester. One partner
("developer") is responsible for the file Lfraction.java,
the other partner ("tester") is responsible for the file LfractionTest.java.
- Development: Add a new method pow for raising
a fraction to a given integer power (by multiplication):
m.pow(0) is
fraction 1/1: new Lfraction(1, 1)
m.pow(1) is equal
to (but not identical to) m
m.pow(-1) is
m.inverse(), check division by zero
m.pow(n) is
defined for n > 1 by the rule: m.times(m.pow(n-1))
m.pow(-n) is m.pow(n).inverse(),
check division by zero
- Testing: Write about 6 - 8 test cases for pow
that cover all the rules listed above and add them to existing
tests (use the junit4
framework, see the test file LfractionTest.java as an
example).
- Make a new commit "Developer: name,
Tester: name" and upload it to
bitbucket (or github), the partner will do the same with their
code. Do this after the testing part is finished.
- Show the commit, the tests and running examples to the
teacher. You can also run tests from the command line if there
is a problem with the IDE.
- The teacher will discuss and ask questions about your work.
Jaanus Pöial