Lab 5 - Fractions

  1. Open your homework in IntelliJ (or other IDE, so that it can be changed), be sure that unit testing works.
  2. 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.
  3. The teacher will assign you a partner for this lab.
  4. 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).
  5. 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.
  6. 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).
  7. 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.
  8. 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
  9. 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).
  10. 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.
  11. 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.
  12. The teacher will discuss and ask questions about your work.

Jaanus Pöial