CPE 102 Program 1c - A Fraction class

Ground Rules

No collaboration is allowed on this program assignment. Your program must be an individual and original effort. Except for any situations explicitly identified in this assignment, if any, you may only receive help from your instructor or the tutors provided by the Computer Science Department. See the Syllabus for the significant consequences for disallowed collaboration and/or plagiarism.


None so far - updates and corrections, if any, will show up here (be sure to refresh this page as necessary).

Due Date and Submission Instructions

Submit the following file(s) on one of the CSL servers using handin as follows:

    file(s): Fraction.java

    touser: eaugusti

    assignment/subdirectory: 102-program01c

  1. Your source code must meet the Programming Guidelines.

  2. Your solution must pass all test of the provided test driver (link and instruction provided below) when compiled and run on any the CSL servers.

  3. Implement a class called Fraction to this specification. Your solution must only have the public methods specified here but you may write addtional private methods if you wish.

  4. Use the minimally necessary number of instance variables of the appropriate type and maintaining encapsulation (private).

  5. You must throw an IllegalArgumentException in certain situations (see specifications for when and where). Exceptions will be covered in greater detail later in the quarter, but for now, here is the Java code necessary to throw the specified exception:

                throw new IllegalArgumentException();

Note that you must write the conditional logic that determines when to throw or not throw the exception.

  1. Start early, read the entire assignment and ask your instructor for any necessary clarifications before writing any code!
  2. Develop incrementally, one method at a time, and use the tests you developed in Program 1b to ensure your work is correct. If you determine your tests are insufficient write more tests! Write a little code, compile, test, debug, fix, repeat until done.

  3. Euclid's Algorithm for finding the greatest common divisor (GCD) is the perferred way to reduce your fraction when necessary. You may use versions of the algorithm that you find on the web but you must provide the URL to the website in a comment block in your code just above the method using the algorithm so I know where you found it.
Testing With the Provided Test Driver
  1. Use your own tests that you developed for Program 1b prior to using the provided test driver.
  2. Do not use the provided test driver (provided on the first due date for the assignment, not before) until your solution is complete and you believe it is correct.

  3. Using the save-as feature of your browser (or wget/curl if you are a cool kid), not cut-and-paste, save P1cTestDriver.java - to be published on the first due date - in the same directory as your Fraction.java file.

  4. Compile both P1cTestDriver.java and Fraction.java and run P1cTestDriver (see How to Compile and Run From the Command Line, as necessary). Remeber that your code will be graded on one of the CSL servers so, to avoid unpleasant grading surprises, be sure to test on any one of those machines at least once after all changes and just before handing in!

Program courtesy of Kurt Mammen.