Cosc 215 - Program #1

Rational Numbers

Due: 1/24/08
Points: 50

For this assignment, you are to write a Java class, Rat, that implements rational number operations. A rational number is the ratio of two integers (the numerator and the denominator), such as 15/2. The denominator cannot be zero. Rational numbers are always written in lowest terms, i.e., 30/12 is reduced to 5/2 by dividing both the numerator and the denominator by the greatest common divisor of 30 and 12 which is 6. The denominator should be positive. The class should include the following constructors:

and implement methods for the following operations:

To find the greatest common denominator, you should use Euclid's algorithm, which can be found at Euclid's algorithm on Wikipedia.

You should also write a main method which exhaustively tests the constructors and methods of the rational number class. Please e-mail me your program (as an attachment) before class on the 24th. Thank you.


If you have questions or comments, email me at simon@mathcs.duq.edu