Lab 5 - Fractions
- Open your homework in IntelliJ (or another IDE, so that it can
be modified), make 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 from the first lab. The test
file LfractionTest.java must also be included in
version control.
- The teacher will assign you a partner for this lab.
- If this is not already the case, implement subtraction of
fractions by adding the opposite (also change the method for
finding the opposite, if necessary). Also implement division of
fractions by 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 for finding the greatest common divisor, preferably by
the Euclidean algorithm.
- If this is not already the case, implement the equals
method using the compareTo method (if necessary,
change the compareTo method, only integers may be
used).
- Divide the roles: developer and tester. One partner
("developer") is responsible for the file Lfraction.java ,
and 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 (using multiplication):
m.pow(0) is
the 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 for 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 the
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